Search in sources :

Example 1 with TestExecution

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

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\"}]");
}
Also used : Path(java.nio.file.Path) TestExecution(com.teamscale.report.testwise.model.TestExecution) Test(org.junit.jupiter.api.Test)

Example 3 with TestExecution

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\"}]");
}
Also used : Path(java.nio.file.Path) TestExecution(com.teamscale.report.testwise.model.TestExecution) Test(org.junit.jupiter.api.Test)

Example 4 with TestExecution

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.");
    }
}
Also used : TestExecution(com.teamscale.report.testwise.model.TestExecution) ResponseBody(okhttp3.ResponseBody)

Example 5 with TestExecution

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.");
}
Also used : ETestExecutionResult(com.teamscale.report.testwise.model.ETestExecutionResult) TestExecution(com.teamscale.report.testwise.model.TestExecution)

Aggregations

TestExecution (com.teamscale.report.testwise.model.TestExecution)18 TestDetails (com.teamscale.client.TestDetails)6 Test (org.junit.jupiter.api.Test)6 ArrayList (java.util.ArrayList)4 TestDescriptor (org.junit.platform.engine.TestDescriptor)4 File (java.io.File)3 UniqueId (org.junit.platform.engine.UniqueId)3 PrioritizableTest (com.teamscale.client.PrioritizableTest)2 PrioritizableTestCluster (com.teamscale.client.PrioritizableTestCluster)2 AgentOptions (com.teamscale.jacoco.agent.options.AgentOptions)2 TestwiseCoverage (com.teamscale.report.testwise.model.TestwiseCoverage)2 TestInfoBuilder (com.teamscale.report.testwise.model.builder.TestInfoBuilder)2 IOException (java.io.IOException)2 Path (java.nio.file.Path)2 ResponseBody (okhttp3.ResponseBody)2 JsonDataException (com.squareup.moshi.JsonDataException)1 ClusteredTestDetails (com.teamscale.client.ClusteredTestDetails)1 JacocoRuntimeController (com.teamscale.jacoco.agent.JacocoRuntimeController)1 Benchmark (com.teamscale.jacoco.agent.util.Benchmark)1 TestwiseCoverageReportWriter (com.teamscale.report.testwise.TestwiseCoverageReportWriter)1