use of com.teamscale.report.testwise.model.TestExecution 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.TestExecution in project teamscale-jacoco-agent by cqse.
the class TestExecutionWriterTest method testMultipleExecutions.
@Test
public void testMultipleExecutions(@TempDir Path tempDir) throws Exception {
Path tempFile = tempDir.resolve("executions.json");
TestExecutionWriter writer = new TestExecutionWriter(tempFile.toFile());
writer.append(new TestExecution("test1", 123, ETestExecutionResult.PASSED));
writer.append(new TestExecution("test2", 123, ETestExecutionResult.PASSED));
writer.append(new TestExecution("test3", 123, ETestExecutionResult.PASSED));
String json = String.join("\n", Files.readAllLines(tempFile));
assertThat(json).isEqualTo("[{\"durationMillis\":123,\"result\":\"PASSED\",\"uniformPath\":\"test1\"}" + ",{\"durationMillis\":123,\"result\":\"PASSED\",\"uniformPath\":\"test2\"}" + ",{\"durationMillis\":123,\"result\":\"PASSED\",\"uniformPath\":\"test3\"}]");
}
use of com.teamscale.report.testwise.model.TestExecution in project teamscale-jacoco-agent by cqse.
the class TestExecutionWriterTest method testOneExecution.
@Test
public void testOneExecution(@TempDir Path tempDir) throws Exception {
Path tempFile = tempDir.resolve("executions.json");
TestExecutionWriter writer = new TestExecutionWriter(tempFile.toFile());
writer.append(new TestExecution("test1", 123, ETestExecutionResult.PASSED));
String json = String.join("\n", Files.readAllLines(tempFile));
assertThat(json).isEqualTo("[{\"durationMillis\":123,\"result\":\"PASSED\",\"uniformPath\":\"test1\"}]");
}
use of com.teamscale.report.testwise.model.TestExecution in project teamscale-jacoco-agent by cqse.
the class RunningTest method endTest.
/**
* Signals to the agent that the test runner has finished executing this test and the result of the test run.
*
* @throws AgentHttpRequestFailedException if communicating with the agent fails or in case of internal errors. This
* method already retries the request once, so this is likely a terminal
* failure. The caller should record this problem appropriately. Coverage
* for subsequent test cases could, however, potentially still be recorded.
* Thus, the caller should continue with test execution and continue
* informing the coverage agent about further test start and end events.
*/
public void endTest(TestRun.TestResultWithMessage result) throws AgentHttpRequestFailedException {
// the agent already records test duration, so we can simply provide a dummy value here
TestExecution execution = new TestExecution(uniformPath, 0L, result.result, result.message);
ResponseBody body = AgentCommunicationUtils.handleRequestError(() -> api.testFinished(uniformPath, execution), "Failed to end coverage recording for test case " + uniformPath + ". Coverage for that test case is most likely lost.");
if (!StringUtils.isBlank(readBodyStringNullSafe(body))) {
throw new AgentConfigurationMismatch("The agent seems to be configured to return test coverage via" + " HTTP to the tia-client (agent option `tia-mode=http`) but you did not instruct the" + " tia-client to handle this. Please either reconfigure the agent or call" + " #endTestAndRetrieveCoverage() instead of this method and handle the returned coverage." + " As it is currently configured, the agent will not store or process the recorded coverage" + " in any way other than sending it to the tia-client via HTTP so it is lost permanently.");
}
}
use of com.teamscale.report.testwise.model.TestExecution in project teamscale-jacoco-agent by cqse.
the class CommandLineInterface method endTest.
private void endTest() throws Exception {
if (arguments.size() < 2) {
throw new InvalidCommandLineException("You must provide the uniform path of the test that is about to be started" + " as the first argument of the endTest command and the test result as the second.");
}
String uniformPath = arguments.remove(0);
ETestExecutionResult result = ETestExecutionResult.valueOf(arguments.remove(0).toUpperCase());
String message = readStdin();
// the agent already records test duration, so we can simply provide a dummy value here
TestExecution execution = new TestExecution(uniformPath, 0L, result, message);
AgentCommunicationUtils.handleRequestError(() -> api.testFinished(uniformPath, execution), "Failed to end coverage recording for test case " + uniformPath + ". Coverage for that test case is most likely lost.");
}
Aggregations