Search in sources :

Example 1 with TestwiseCoverage

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

the class CoverageToTeamscaleStrategyTest method testValidCallSequence.

@Test
public void testValidCallSequence() throws Exception {
    List<PrioritizableTestCluster> clusters = Collections.singletonList(new PrioritizableTestCluster("cluster", Collections.singletonList(new PrioritizableTest("mytest"))));
    when(client.getImpactedTests(any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(Response.success(clusters));
    TestwiseCoverage testwiseCoverage = getDummyTestwiseCoverage("mytest");
    when(reportGenerator.convert(any(File.class))).thenReturn(testwiseCoverage);
    AgentOptions options = mockOptions();
    JacocoRuntimeController controller = mock(JacocoRuntimeController.class);
    CoverageToTeamscaleStrategy strategy = new CoverageToTeamscaleStrategy(controller, options, reportGenerator);
    strategy.testRunStart(Collections.singletonList(new ClusteredTestDetails("mytest", "mytest", "content", "cluster")), false, true, true, null);
    strategy.testStart("mytest");
    strategy.testEnd("mytest", new TestExecution("mytest", 0L, ETestExecutionResult.PASSED));
    strategy.testRunEnd();
    verify(client).uploadReport(eq(EReportFormat.TESTWISE_COVERAGE), matches("\\Q{\"tests\":[{\"content\":\"content\",\"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) ClusteredTestDetails(com.teamscale.client.ClusteredTestDetails) JacocoRuntimeController(com.teamscale.jacoco.agent.JacocoRuntimeController) TestExecution(com.teamscale.report.testwise.model.TestExecution) PrioritizableTestCluster(com.teamscale.client.PrioritizableTestCluster) File(java.io.File) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions) PrioritizableTest(com.teamscale.client.PrioritizableTest) PrioritizableTest(com.teamscale.client.PrioritizableTest) Test(org.junit.jupiter.api.Test)

Example 2 with TestwiseCoverage

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

the class CoverageToTeamscaleStrategyTest method getDummyTestwiseCoverage.

/**
 * Returns a dummy testwise coverage object for a test with the given name that covers a few lines of Main.java.
 */
protected static TestwiseCoverage getDummyTestwiseCoverage(String test) {
    TestCoverageBuilder testCoverageBuilder = new TestCoverageBuilder(test);
    FileCoverageBuilder fileCoverageBuilder = new FileCoverageBuilder("src/main/java", "Main.java");
    fileCoverageBuilder.addLineRange(1, 4);
    testCoverageBuilder.add(fileCoverageBuilder);
    TestwiseCoverage testwiseCoverage = new TestwiseCoverage();
    testwiseCoverage.add(testCoverageBuilder);
    return testwiseCoverage;
}
Also used : TestwiseCoverage(com.teamscale.report.testwise.model.TestwiseCoverage) TestCoverageBuilder(com.teamscale.report.testwise.model.builder.TestCoverageBuilder) FileCoverageBuilder(com.teamscale.report.testwise.model.builder.FileCoverageBuilder)

Example 3 with TestwiseCoverage

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

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

the class JaCoCoTestwiseReportGenerator method convert.

/**
 * Converts the given dumps to a report.
 */
public TestwiseCoverage convert(File executionDataFile) throws IOException, CoverageGenerationException {
    TestwiseCoverage testwiseCoverage = new TestwiseCoverage();
    CachingExecutionDataReader.DumpConsumer dumpConsumer = executionDataReader.buildCoverageConsumer(locationIncludeFilter, testwiseCoverage::add);
    readAndConsumeDumps(executionDataFile, dumpConsumer);
    return testwiseCoverage;
}
Also used : TestwiseCoverage(com.teamscale.report.testwise.model.TestwiseCoverage)

Example 5 with TestwiseCoverage

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

the class JaCoCoTestwiseReportGeneratorTest method runReportGenerator.

private String runReportGenerator(String testDataFolder, String execFileName) throws Exception {
    File classFileFolder = useTestFile(testDataFolder);
    ClasspathWildcardIncludeFilter includeFilter = new ClasspathWildcardIncludeFilter(null, null);
    TestwiseCoverage testwiseCoverage = new JaCoCoTestwiseReportGenerator(Collections.singletonList(classFileFolder), includeFilter, EDuplicateClassFileBehavior.IGNORE, mock(ILogger.class)).convert(useTestFile(execFileName));
    return ReportUtils.getTestwiseCoverageReportAsString(generateDummyReportFrom(testwiseCoverage));
}
Also used : TestwiseCoverage(com.teamscale.report.testwise.model.TestwiseCoverage) ClasspathWildcardIncludeFilter(com.teamscale.report.util.ClasspathWildcardIncludeFilter) File(java.io.File)

Aggregations

TestwiseCoverage (com.teamscale.report.testwise.model.TestwiseCoverage)6 File (java.io.File)4 AgentOptions (com.teamscale.jacoco.agent.options.AgentOptions)3 TestExecution (com.teamscale.report.testwise.model.TestExecution)3 ClusteredTestDetails (com.teamscale.client.ClusteredTestDetails)2 PrioritizableTest (com.teamscale.client.PrioritizableTest)2 JacocoRuntimeController (com.teamscale.jacoco.agent.JacocoRuntimeController)2 TestCoverageBuilder (com.teamscale.report.testwise.model.builder.TestCoverageBuilder)2 Test (org.junit.jupiter.api.Test)2 JsonAdapter (com.squareup.moshi.JsonAdapter)1 Moshi (com.squareup.moshi.Moshi)1 EReportFormat (com.teamscale.client.EReportFormat)1 PrioritizableTestCluster (com.teamscale.client.PrioritizableTestCluster)1 TeamscaleConfig (com.teamscale.jacoco.agent.upload.teamscale.TeamscaleConfig)1 LoggingUtils (com.teamscale.jacoco.agent.util.LoggingUtils)1 JaCoCoTestwiseReportGenerator (com.teamscale.report.testwise.jacoco.JaCoCoTestwiseReportGenerator)1 CoverageGenerationException (com.teamscale.report.testwise.jacoco.cache.CoverageGenerationException)1 TestwiseCoverageReport (com.teamscale.report.testwise.model.TestwiseCoverageReport)1 FileCoverageBuilder (com.teamscale.report.testwise.model.builder.FileCoverageBuilder)1 TestwiseCoverageReportBuilder (com.teamscale.report.testwise.model.builder.TestwiseCoverageReportBuilder)1