Search in sources :

Example 1 with TestRun

use of com.teamscale.tia.client.TestRun in project teamscale-jacoco-agent by cqse.

the class TestwiseCoverageAgentTest method testAccessViaTiaClientAndReportUploadToTeamscale.

@Test
public void testAccessViaTiaClientAndReportUploadToTeamscale() throws Exception {
    List<ClusteredTestDetails> availableTests = Arrays.asList(new ClusteredTestDetails("test1", "test1", "content", "cluster"), new ClusteredTestDetails("test2", "test2", "content", "cluster"));
    List<PrioritizableTestCluster> impactedClusters = Collections.singletonList(new PrioritizableTestCluster("cluster", Collections.singletonList(new PrioritizableTest("test2"))));
    when(client.getImpactedTests(any(), any(), any(), any(), anyBoolean(), anyBoolean(), anyBoolean())).thenReturn(Response.success(impactedClusters));
    when(reportGenerator.convert(any(File.class))).thenReturn(CoverageToTeamscaleStrategyTest.getDummyTestwiseCoverage("test2"));
    int port = PORT_COUNTER.incrementAndGet();
    AgentOptions options = mockOptions(port);
    when(options.createTempFile(any(), any())).thenReturn(new File(tempDir, "test"));
    new TestwiseCoverageAgent(options, null, reportGenerator);
    TiaAgent agent = new TiaAgent(false, HttpUrl.get("http://localhost:" + port));
    TestRunWithClusteredSuggestions testRun = agent.startTestRun(availableTests);
    assertThat(testRun.getPrioritizedClusters()).hasSize(1);
    assertThat(testRun.getPrioritizedClusters().get(0).tests).hasSize(1);
    PrioritizableTest test = testRun.getPrioritizedClusters().get(0).tests.get(0);
    assertThat(test.uniformPath).isEqualTo("test2");
    RunningTest runningTest = testRun.startTest(test.uniformPath);
    runningTest.endTest(new TestRun.TestResultWithMessage(ETestExecutionResult.PASSED, "message"));
    testRun.endTestRun();
    verify(client).uploadReport(eq(EReportFormat.TESTWISE_COVERAGE), matches("\\Q{\"tests\":[{\"content\":\"content\",\"paths\":[],\"sourcePath\":\"test1\",\"uniformPath\":\"test1\"},{\"content\":\"content\",\"duration\":\\E[^,]*\\Q,\"message\":\"message\",\"paths\":[{\"files\":[{\"coveredLines\":\"1-4\",\"fileName\":\"Main.java\"}],\"path\":\"src/main/java\"}],\"result\":\"PASSED\",\"sourcePath\":\"test2\",\"uniformPath\":\"test2\"}]}\\E"), any(), any(), any(), any());
}
Also used : RunningTest(com.teamscale.tia.client.RunningTest) ClusteredTestDetails(com.teamscale.client.ClusteredTestDetails) TiaAgent(com.teamscale.tia.client.TiaAgent) TestRunWithClusteredSuggestions(com.teamscale.tia.client.TestRunWithClusteredSuggestions) PrioritizableTestCluster(com.teamscale.client.PrioritizableTestCluster) PrioritizableTest(com.teamscale.client.PrioritizableTest) TestRun(com.teamscale.tia.client.TestRun) File(java.io.File) AgentOptions(com.teamscale.jacoco.agent.options.AgentOptions) PrioritizableTest(com.teamscale.client.PrioritizableTest) Test(org.junit.jupiter.api.Test) RunningTest(com.teamscale.tia.client.RunningTest)

Example 2 with TestRun

use of com.teamscale.tia.client.TestRun in project teamscale-jacoco-agent by cqse.

the class CustomTestFramework method runTestsWithTia.

/**
 * Talks to the TIA agent and runs all impacted tests. Also uploads a coverage report at the end.
 */
public void runTestsWithTia() throws AgentHttpRequestFailedException {
    TiaAgent agent = new TiaAgent(false, HttpUrl.get("http://localhost:" + agentPort));
    TestRun testRun = agent.startTestRunWithoutTestSelection();
    for (String uniformPath : allTests.keySet()) {
        Runnable runnable = allTests.get(uniformPath);
        RunningTest runningTest = testRun.startTest(uniformPath);
        TestInfo testInfo;
        try {
            runnable.run();
            testInfo = runningTest.endTestAndRetrieveCoverage(new TestRun.TestResultWithMessage(ETestExecutionResult.PASSED, ""));
        } catch (Throwable t) {
            testInfo = runningTest.endTestAndRetrieveCoverage(new TestRun.TestResultWithMessage(ETestExecutionResult.FAILURE, t.getMessage()));
        }
        testInfos.add(testInfo);
    }
}
Also used : RunningTest(com.teamscale.tia.client.RunningTest) TiaAgent(com.teamscale.tia.client.TiaAgent) TestRun(com.teamscale.tia.client.TestRun) TestInfo(com.teamscale.report.testwise.model.TestInfo)

Aggregations

RunningTest (com.teamscale.tia.client.RunningTest)2 TestRun (com.teamscale.tia.client.TestRun)2 TiaAgent (com.teamscale.tia.client.TiaAgent)2 ClusteredTestDetails (com.teamscale.client.ClusteredTestDetails)1 PrioritizableTest (com.teamscale.client.PrioritizableTest)1 PrioritizableTestCluster (com.teamscale.client.PrioritizableTestCluster)1 AgentOptions (com.teamscale.jacoco.agent.options.AgentOptions)1 TestInfo (com.teamscale.report.testwise.model.TestInfo)1 TestRunWithClusteredSuggestions (com.teamscale.tia.client.TestRunWithClusteredSuggestions)1 File (java.io.File)1 Test (org.junit.jupiter.api.Test)1