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