Search in sources :

Example 1 with TestwiseCoverageReport

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

the class CoverageToTeamscaleStrategy method createTestwiseCoverageReport.

/**
 * Creates a testwise coverage report from the coverage collected in {@link #testExecFile} and the test execution
 * information in {@link #testExecutions}.
 */
private String createTestwiseCoverageReport() throws IOException, CoverageGenerationException {
    List<String> executionUniformPaths = testExecutions.stream().map(execution -> {
        if (execution == null) {
            return null;
        } else {
            return execution.getUniformPath();
        }
    }).collect(toList());
    logger.debug("Creating testwise coverage form available tests `{}`, test executions `{}` and exec file", availableTests.stream().map(test -> test.uniformPath).collect(toList()), executionUniformPaths);
    TestwiseCoverage testwiseCoverage = reportGenerator.convert(testExecFile);
    logger.debug("Created testwise coverage report (containing coverage for tests `{}`)", testwiseCoverage.getTests().stream().map(TestCoverageBuilder::getUniformPath).collect(toList()));
    TestwiseCoverageReport report = TestwiseCoverageReportBuilder.createFrom(availableTests, testwiseCoverage.getTests(), testExecutions);
    testExecFile.delete();
    testExecFile = null;
    availableTests.clear();
    testExecutions.clear();
    return testwiseCoverageReportJsonAdapter.toJson(report);
}
Also used : FileSystemUtils(org.conqat.lib.commons.filesystem.FileSystemUtils) JsonAdapter(com.squareup.moshi.JsonAdapter) Logger(org.slf4j.Logger) JaCoCoTestwiseReportGenerator(com.teamscale.report.testwise.jacoco.JaCoCoTestwiseReportGenerator) TestwiseCoverageReport(com.teamscale.report.testwise.model.TestwiseCoverageReport) Moshi(com.squareup.moshi.Moshi) IOException(java.io.IOException) TestCoverageBuilder(com.teamscale.report.testwise.model.builder.TestCoverageBuilder) TestwiseCoverage(com.teamscale.report.testwise.model.TestwiseCoverage) File(java.io.File) ArrayList(java.util.ArrayList) TeamscaleConfig(com.teamscale.jacoco.agent.upload.teamscale.TeamscaleConfig) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) LoggingUtils(com.teamscale.jacoco.agent.util.LoggingUtils) CoverageGenerationException(com.teamscale.report.testwise.jacoco.cache.CoverageGenerationException) ClusteredTestDetails(com.teamscale.client.ClusteredTestDetails) TestwiseCoverageReportBuilder(com.teamscale.report.testwise.model.builder.TestwiseCoverageReportBuilder) EReportFormat(com.teamscale.client.EReportFormat) JacocoRuntimeController(com.teamscale.jacoco.agent.JacocoRuntimeController) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions) TestExecution(com.teamscale.report.testwise.model.TestExecution) TestwiseCoverage(com.teamscale.report.testwise.model.TestwiseCoverage) TestCoverageBuilder(com.teamscale.report.testwise.model.builder.TestCoverageBuilder) TestwiseCoverageReport(com.teamscale.report.testwise.model.TestwiseCoverageReport)

Example 2 with TestwiseCoverageReport

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

the class TiaClientSystemTest method systemTest.

@Test
public void systemTest() throws Exception {
    TeamscaleMockServer teamscaleMockServer = new TeamscaleMockServer(FAKE_TEAMSCALE_PORT, "testFoo", "testBar");
    CustomTestFramework customTestFramework = new CustomTestFramework(AGENT_PORT);
    customTestFramework.runTestsWithTia();
    assertThat(teamscaleMockServer.uploadedReports).hasSize(1);
    TestwiseCoverageReport report = teamscaleMockServer.parseUploadedTestwiseCoverageReport(0);
    assertThat(report.tests).hasSize(2);
    assertAll(() -> {
        assertThat(report.tests).extracting(test -> test.uniformPath).containsExactlyInAnyOrder("testBar", "testFoo");
        assertThat(report.tests).extracting(test -> test.result).containsExactlyInAnyOrder(ETestExecutionResult.FAILURE, ETestExecutionResult.PASSED);
        assertThat(report.tests).extracting(TiaClientSystemTest::getCoverageString).containsExactlyInAnyOrder("SystemUnderTest.java:4,13", "SystemUnderTest.java:4,8");
    });
}
Also used : Test(org.junit.jupiter.api.Test) TestInfo(com.teamscale.report.testwise.model.TestInfo) TeamscaleMockServer(com.teamscale.test.commons.TeamscaleMockServer) TestwiseCoverageReport(com.teamscale.report.testwise.model.TestwiseCoverageReport) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) CustomTestFramework(testframework.CustomTestFramework) Collectors(java.util.stream.Collectors) ETestExecutionResult(com.teamscale.report.testwise.model.ETestExecutionResult) TeamscaleMockServer(com.teamscale.test.commons.TeamscaleMockServer) TestwiseCoverageReport(com.teamscale.report.testwise.model.TestwiseCoverageReport) CustomTestFramework(testframework.CustomTestFramework) Test(org.junit.jupiter.api.Test)

Example 3 with TestwiseCoverageReport

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

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

the class JUnitRunListenerSystemTest method testJUnit4RunListener.

/**
 * Tests the JUnit 4 {@link org.junit.runner.notification.RunListener}.
 */
@Test
public void testJUnit4RunListener() throws Exception {
    runMavenTests("junit4-maven-project");
    assertThat(teamscaleMockServer.uploadedReports).hasSize(1);
    TestwiseCoverageReport report = teamscaleMockServer.parseUploadedTestwiseCoverageReport(0);
    assertThat(report.tests).hasSize(1);
    assertAll(() -> {
        assertThat(report.tests).extracting(test -> test.uniformPath).containsExactlyInAnyOrder("JUnit4Test/testAdd");
        assertThat(report.tests).extracting(test -> test.result).containsExactlyInAnyOrder(ETestExecutionResult.PASSED);
        assertThat(report.tests).extracting(JUnitRunListenerSystemTest::getCoverageString).containsExactly("SystemUnderTest.java:3,6");
    });
}
Also used : Test(org.junit.jupiter.api.Test) TestInfo(com.teamscale.report.testwise.model.TestInfo) TeamscaleMockServer(com.teamscale.test.commons.TeamscaleMockServer) BeforeEach(org.junit.jupiter.api.BeforeEach) TestwiseCoverageReport(com.teamscale.report.testwise.model.TestwiseCoverageReport) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) ProcessUtils(org.conqat.lib.commons.io.ProcessUtils) Collectors(java.util.stream.Collectors) ETestExecutionResult(com.teamscale.report.testwise.model.ETestExecutionResult) File(java.io.File) TestwiseCoverageReport(com.teamscale.report.testwise.model.TestwiseCoverageReport) Test(org.junit.jupiter.api.Test)

Example 5 with TestwiseCoverageReport

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

the class JUnitRunListenerSystemTest method testJUnit5TestExecutionListener.

/**
 * Tests the JUnit 5 {@link org.junit.platform.launcher.TestExecutionListener}.
 */
@Test
public void testJUnit5TestExecutionListener() throws Exception {
    runMavenTests("junit5-maven-project");
    assertThat(teamscaleMockServer.uploadedReports).hasSize(1);
    TestwiseCoverageReport report = teamscaleMockServer.parseUploadedTestwiseCoverageReport(0);
    assertThat(report.tests).hasSize(2);
    assertAll(() -> {
        assertThat(report.tests).extracting(test -> test.uniformPath).containsExactlyInAnyOrder("JUnit4ExecutedWithJUnit5Test/testAdd()", "JUnit5Test/testAdd()");
        assertThat(report.tests).extracting(test -> test.result).containsExactlyInAnyOrder(ETestExecutionResult.PASSED, ETestExecutionResult.PASSED);
        assertThat(report.tests).extracting(JUnitRunListenerSystemTest::getCoverageString).containsExactly("SystemUnderTest.java:3,6", "SystemUnderTest.java:3,6");
    });
}
Also used : Test(org.junit.jupiter.api.Test) TestInfo(com.teamscale.report.testwise.model.TestInfo) TeamscaleMockServer(com.teamscale.test.commons.TeamscaleMockServer) BeforeEach(org.junit.jupiter.api.BeforeEach) TestwiseCoverageReport(com.teamscale.report.testwise.model.TestwiseCoverageReport) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) IOException(java.io.IOException) Assertions.assertAll(org.junit.jupiter.api.Assertions.assertAll) ProcessUtils(org.conqat.lib.commons.io.ProcessUtils) Collectors(java.util.stream.Collectors) ETestExecutionResult(com.teamscale.report.testwise.model.ETestExecutionResult) File(java.io.File) TestwiseCoverageReport(com.teamscale.report.testwise.model.TestwiseCoverageReport) Test(org.junit.jupiter.api.Test)

Aggregations

TestwiseCoverageReport (com.teamscale.report.testwise.model.TestwiseCoverageReport)5 TestInfo (com.teamscale.report.testwise.model.TestInfo)4 ETestExecutionResult (com.teamscale.report.testwise.model.ETestExecutionResult)3 TeamscaleMockServer (com.teamscale.test.commons.TeamscaleMockServer)3 File (java.io.File)3 IOException (java.io.IOException)3 Collectors (java.util.stream.Collectors)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 Assertions.assertAll (org.junit.jupiter.api.Assertions.assertAll)3 Test (org.junit.jupiter.api.Test)3 ArrayList (java.util.ArrayList)2 ProcessUtils (org.conqat.lib.commons.io.ProcessUtils)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2 JsonAdapter (com.squareup.moshi.JsonAdapter)1 Moshi (com.squareup.moshi.Moshi)1 ClusteredTestDetails (com.teamscale.client.ClusteredTestDetails)1 EReportFormat (com.teamscale.client.EReportFormat)1 JacocoRuntimeController (com.teamscale.jacoco.agent.JacocoRuntimeController)1 AgentOptions (com.teamscale.jacoco.agent.options.AgentOptions)1 TeamscaleConfig (com.teamscale.jacoco.agent.upload.teamscale.TeamscaleConfig)1