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;
}
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);
}
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);
}
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);
}
}
Aggregations