Search in sources :

Example 11 with TestExecution

use of com.teamscale.report.testwise.model.TestExecution 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 12 with TestExecution

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

the class TestInfoFactory method createFor.

/**
 * Converts the given {@link TestCoverageBuilder} to a {@link TestInfo} using the internally stored test details and
 * test executions.
 */
public TestInfo createFor(TestCoverageBuilder testCoverageBuilder) {
    String resolvedUniformPath = resolveUniformPath(testCoverageBuilder.getUniformPath());
    processedTestUniformPaths.add(resolvedUniformPath);
    TestInfoBuilder container = new TestInfoBuilder(resolvedUniformPath);
    container.setCoverage(testCoverageBuilder);
    TestDetails testDetails = testDetailsMap.get(resolvedUniformPath);
    if (testDetails == null) {
        System.err.println("No test details found for " + resolvedUniformPath);
    }
    container.setDetails(testDetails);
    TestExecution execution = testExecutionsMap.get(resolvedUniformPath);
    if (execution == null) {
        System.err.println("No test execution found for " + resolvedUniformPath);
    }
    container.setExecution(execution);
    return container.build();
}
Also used : TestExecution(com.teamscale.report.testwise.model.TestExecution) TestInfoBuilder(com.teamscale.report.testwise.model.builder.TestInfoBuilder) TestDetails(com.teamscale.client.TestDetails)

Example 13 with TestExecution

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

the class TestwiseCoverageCollectingExecutionListener method executionSkipped.

@Override
public void executionSkipped(TestDescriptor testDescriptor, String reason) {
    if (!TestDescriptorUtils.isTestRepresentative(testDescriptor)) {
        delegateEngineExecutionListener.executionStarted(testDescriptor);
        testDescriptor.getChildren().forEach(child -> this.executionSkipped(child, reason));
        delegateEngineExecutionListener.executionFinished(testDescriptor, TestExecutionResult.successful());
        return;
    }
    testDescriptorResolver.getUniformPath(testDescriptor).ifPresent(testUniformPath -> {
        if (!AutoSkippingEngineExecutionListener.TEST_NOT_IMPACTED_REASON.equals(reason)) {
            testExecutions.add(new TestExecution(testUniformPath, 0L, ETestExecutionResult.SKIPPED, reason));
        }
        delegateEngineExecutionListener.executionSkipped(testDescriptor, reason);
    });
}
Also used : TestExecution(com.teamscale.report.testwise.model.TestExecution)

Example 14 with TestExecution

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

the class JaCoCoTestwiseReportGeneratorTest method generateDummyReportFrom.

/**
 * Generates a dummy coverage report object that wraps the given {@link TestwiseCoverage}.
 */
public static TestwiseCoverageReport generateDummyReportFrom(TestwiseCoverage testwiseCoverage) {
    ArrayList<TestDetails> testDetails = new ArrayList<>();
    for (TestCoverageBuilder test : testwiseCoverage.getTests()) {
        testDetails.add(new TestDetails(test.getUniformPath(), "/path/to/source", "content"));
    }
    ArrayList<TestExecution> testExecutions = new ArrayList<>();
    for (TestCoverageBuilder test : testwiseCoverage.getTests()) {
        testExecutions.add(new TestExecution(test.getUniformPath(), test.getUniformPath().length(), ETestExecutionResult.PASSED));
    }
    return TestwiseCoverageReportBuilder.createFrom(testDetails, testwiseCoverage.getTests(), testExecutions);
}
Also used : TestExecution(com.teamscale.report.testwise.model.TestExecution) TestCoverageBuilder(com.teamscale.report.testwise.model.builder.TestCoverageBuilder) ArrayList(java.util.ArrayList) TestDetails(com.teamscale.client.TestDetails)

Example 15 with TestExecution

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

the class CoverageToTeamscaleStrategyTest method shouldRecordCoverageForTestsEvenIfNotProvidedAsAvailableTest.

@Test
public void shouldRecordCoverageForTestsEvenIfNotProvidedAsAvailableTest() throws Exception {
    AgentOptions options = mockOptions();
    CoverageToTeamscaleStrategy strategy = new CoverageToTeamscaleStrategy(controller, options, reportGenerator);
    TestwiseCoverage testwiseCoverage = getDummyTestwiseCoverage("mytest");
    when(reportGenerator.convert(any(File.class))).thenReturn(testwiseCoverage);
    // we skip testRunStart and don't provide any available tests
    strategy.testStart("mytest");
    strategy.testEnd("mytest", new TestExecution("mytest", 0L, ETestExecutionResult.PASSED));
    strategy.testRunEnd();
    verify(client).uploadReport(eq(EReportFormat.TESTWISE_COVERAGE), matches("\\Q{\"tests\":[{\"duration\":\\E[^,]*\\Q,\"paths\":[{\"files\":[{\"coveredLines\":\"1-4\",\"fileName\":\"Main.java\"}],\"path\":\"src/main/java\"}],\"result\":\"PASSED\",\"sourcePath\":\"mytest\",\"uniformPath\":\"mytest\"}]}\\E"), any(), any(), any(), any());
}
Also used : TestwiseCoverage(com.teamscale.report.testwise.model.TestwiseCoverage) TestExecution(com.teamscale.report.testwise.model.TestExecution) File(java.io.File) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions) PrioritizableTest(com.teamscale.client.PrioritizableTest) Test(org.junit.jupiter.api.Test)

Aggregations

TestExecution (com.teamscale.report.testwise.model.TestExecution)18 TestDetails (com.teamscale.client.TestDetails)6 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)4 TestDescriptor (org.junit.platform.engine.TestDescriptor)4 File (java.io.File)3 UniqueId (org.junit.platform.engine.UniqueId)3 PrioritizableTest (com.teamscale.client.PrioritizableTest)2 PrioritizableTestCluster (com.teamscale.client.PrioritizableTestCluster)2 AgentOptions (com.teamscale.jacoco.agent.options.AgentOptions)2 TestwiseCoverage (com.teamscale.report.testwise.model.TestwiseCoverage)2 TestInfoBuilder (com.teamscale.report.testwise.model.builder.TestInfoBuilder)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ResponseBody (okhttp3.ResponseBody)2 JsonDataException (com.squareup.moshi.JsonDataException)1 ClusteredTestDetails (com.teamscale.client.ClusteredTestDetails)1 JacocoRuntimeController (com.teamscale.jacoco.agent.JacocoRuntimeController)1 Benchmark (com.teamscale.jacoco.agent.util.Benchmark)1 TestwiseCoverageReportWriter (com.teamscale.report.testwise.TestwiseCoverageReportWriter)1