Search in sources :

Example 1 with TestCoverageBuilder

use of com.teamscale.report.testwise.model.builder.TestCoverageBuilder 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 2 with TestCoverageBuilder

use of com.teamscale.report.testwise.model.builder.TestCoverageBuilder 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 3 with TestCoverageBuilder

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

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

the class TestwiseCoverage method add.

/**
 * Adds the {@link TestCoverageBuilder} to the map.
 * If there is already a test with the same ID the coverage is merged.
 */
public void add(TestCoverageBuilder coverage) {
    if (coverage == null || coverage.isEmpty()) {
        return;
    }
    if (tests.containsKey(coverage.getUniformPath())) {
        TestCoverageBuilder testCoverage = tests.get(coverage.getUniformPath());
        testCoverage.addAll(coverage.getFiles());
    } else {
        tests.put(coverage.getUniformPath(), coverage);
    }
}
Also used : TestCoverageBuilder(com.teamscale.report.testwise.model.builder.TestCoverageBuilder)

Aggregations

TestCoverageBuilder (com.teamscale.report.testwise.model.builder.TestCoverageBuilder)4 TestExecution (com.teamscale.report.testwise.model.TestExecution)2 TestwiseCoverage (com.teamscale.report.testwise.model.TestwiseCoverage)2 ArrayList (java.util.ArrayList)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 TestDetails (com.teamscale.client.TestDetails)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 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 File (java.io.File)1 IOException (java.io.IOException)1