Search in sources :

Example 1 with TestInfo

use of com.teamscale.report.testwise.model.TestInfo in project teamscale-jacoco-agent by cqse.

the class CustomTestFramework method runTestsWithTia.

/**
 * Talks to the TIA agent and runs all impacted tests. Also uploads a coverage report at the end.
 */
public void runTestsWithTia() throws AgentHttpRequestFailedException {
    TiaAgent agent = new TiaAgent(false, HttpUrl.get("http://localhost:" + agentPort));
    TestRun testRun = agent.startTestRunWithoutTestSelection();
    for (String uniformPath : allTests.keySet()) {
        Runnable runnable = allTests.get(uniformPath);
        RunningTest runningTest = testRun.startTest(uniformPath);
        TestInfo testInfo;
        try {
            runnable.run();
            testInfo = runningTest.endTestAndRetrieveCoverage(new TestRun.TestResultWithMessage(ETestExecutionResult.PASSED, ""));
        } catch (Throwable t) {
            testInfo = runningTest.endTestAndRetrieveCoverage(new TestRun.TestResultWithMessage(ETestExecutionResult.FAILURE, t.getMessage()));
        }
        testInfos.add(testInfo);
    }
}
Also used : RunningTest(com.teamscale.tia.client.RunningTest) TiaAgent(com.teamscale.tia.client.TiaAgent) TestRun(com.teamscale.tia.client.TestRun) TestInfo(com.teamscale.report.testwise.model.TestInfo)

Example 2 with TestInfo

use of com.teamscale.report.testwise.model.TestInfo in project teamscale-jacoco-agent by cqse.

the class TestInfoFactory method createTestInfosWithoutCoverage.

/**
 * Returns {@link TestInfo}s for all tests that have not been used yet in {@link #createFor(TestCoverageBuilder)}.
 */
public List<TestInfo> createTestInfosWithoutCoverage() {
    ArrayList<TestInfo> results = new ArrayList<>();
    for (TestDetails testDetails : testDetailsMap.values()) {
        if (!processedTestUniformPaths.contains(testDetails.uniformPath)) {
            TestInfoBuilder testInfo = new TestInfoBuilder(testDetails.uniformPath);
            testInfo.setDetails(testDetails);
            testInfo.setExecution(testExecutionsMap.get(testDetails.uniformPath));
            results.add(testInfo.build());
            processedTestUniformPaths.add(testDetails.uniformPath);
        }
    }
    for (TestExecution testExecution : testExecutionsMap.values()) {
        if (!processedTestUniformPaths.contains(testExecution.getUniformPath())) {
            System.err.println("Test " + testExecution.getUniformPath() + " was executed but no coverage was found. " + "Please make sure that you did provide all relevant exec files and that the test IDs passed to " + "the agent match the ones from the provided test execution list.");
            processedTestUniformPaths.add(testExecution.getUniformPath());
        }
    }
    return results;
}
Also used : TestExecution(com.teamscale.report.testwise.model.TestExecution) ArrayList(java.util.ArrayList) TestInfoBuilder(com.teamscale.report.testwise.model.builder.TestInfoBuilder) TestInfo(com.teamscale.report.testwise.model.TestInfo) TestDetails(com.teamscale.client.TestDetails)

Example 3 with TestInfo

use of com.teamscale.report.testwise.model.TestInfo in project teamscale-jacoco-agent by cqse.

the class TestwiseCoverageReportBuilder method build.

private TestwiseCoverageReport build() {
    TestwiseCoverageReport report = new TestwiseCoverageReport();
    List<TestInfoBuilder> testInfoBuilders = new ArrayList<>(tests.values());
    testInfoBuilders.sort(Comparator.comparing(TestInfoBuilder::getUniformPath));
    for (TestInfoBuilder testInfoBuilder : testInfoBuilders) {
        TestInfo testInfo = testInfoBuilder.build();
        if (testInfo == null) {
            System.err.println("No coverage for test '" + testInfoBuilder.getUniformPath() + "'");
            continue;
        }
        report.tests.add(testInfo);
    }
    return report;
}
Also used : ArrayList(java.util.ArrayList) TestInfo(com.teamscale.report.testwise.model.TestInfo) TestwiseCoverageReport(com.teamscale.report.testwise.model.TestwiseCoverageReport)

Example 4 with TestInfo

use of com.teamscale.report.testwise.model.TestInfo in project teamscale-jacoco-agent by cqse.

the class CoverageViaHttpStrategy method testEnd.

@Override
public String testEnd(String test, TestExecution testExecution) throws JacocoRuntimeController.DumpException, CoverageGenerationException {
    super.testEnd(test, testExecution);
    TestInfoBuilder builder = new TestInfoBuilder(test);
    Dump dump = controller.dumpAndReset();
    builder.setCoverage(reportGenerator.convert(dump));
    if (testExecution != null) {
        builder.setExecution(testExecution);
    }
    TestInfo testInfo = builder.build();
    String testInfoJson = testInfoJsonAdapter.toJson(testInfo);
    logger.debug("Generated test info {}", testInfoJson);
    return testInfoJson;
}
Also used : Dump(com.teamscale.report.jacoco.dump.Dump) TestInfoBuilder(com.teamscale.report.testwise.model.builder.TestInfoBuilder) TestInfo(com.teamscale.report.testwise.model.TestInfo)

Aggregations

TestInfo (com.teamscale.report.testwise.model.TestInfo)4 TestInfoBuilder (com.teamscale.report.testwise.model.builder.TestInfoBuilder)2 ArrayList (java.util.ArrayList)2 TestDetails (com.teamscale.client.TestDetails)1 Dump (com.teamscale.report.jacoco.dump.Dump)1 TestExecution (com.teamscale.report.testwise.model.TestExecution)1 TestwiseCoverageReport (com.teamscale.report.testwise.model.TestwiseCoverageReport)1 RunningTest (com.teamscale.tia.client.RunningTest)1 TestRun (com.teamscale.tia.client.TestRun)1 TiaAgent (com.teamscale.tia.client.TiaAgent)1