Search in sources :

Example 1 with PrioritizableTest

use of com.teamscale.client.PrioritizableTest 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 PrioritizableTest

use of com.teamscale.client.PrioritizableTest 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 3 with PrioritizableTest

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

the class AvailableTests method convertToUniqueIds.

/**
 * Converts the {@link PrioritizableTest}s which are match the {@link UniqueId}s returned by the {@link TestEngine}s
 * used by the {@link ImpactedTestEngine}.
 */
public Set<UniqueId> convertToUniqueIds(List<PrioritizableTest> impactedTests) {
    Set<UniqueId> list = new HashSet<>();
    for (PrioritizableTest impactedTest : impactedTests) {
        LOGGER.info(() -> impactedTest.uniformPath + " " + impactedTest.selectionReason);
        UniqueId testUniqueId = uniformPathToUniqueIdMapping.get(impactedTest.uniformPath);
        if (testUniqueId == null) {
            LOGGER.error(() -> "Retrieved invalid test '" + impactedTest.uniformPath + "' from Teamscale server!");
            LOGGER.error(() -> "The following seem related:");
            uniformPathToUniqueIdMapping.keySet().stream().sorted(Comparator.comparing(testPath -> StringUtils.editDistance(impactedTest.uniformPath, testPath))).limit(5).forEach(testAlternative -> LOGGER.error(() -> " - " + testAlternative));
            LOGGER.error(() -> "Falling back to execute all...");
            return new HashSet<>(uniformPathToUniqueIdMapping.values());
        }
        list.add(testUniqueId);
    }
    return list;
}
Also used : ImpactedTestEngine(com.teamscale.test_impacted.engine.ImpactedTestEngine) Logger(org.junit.platform.commons.logging.Logger) TestEngine(org.junit.platform.engine.TestEngine) Set(java.util.Set) HashMap(java.util.HashMap) UniqueId(org.junit.platform.engine.UniqueId) PrioritizableTest(com.teamscale.client.PrioritizableTest) StringUtils(com.teamscale.client.StringUtils) LoggerFactory(org.junit.platform.commons.logging.LoggerFactory) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) List(java.util.List) TestDetails(com.teamscale.client.TestDetails) Map(java.util.Map) ClusteredTestDetails(com.teamscale.client.ClusteredTestDetails) Comparator(java.util.Comparator) UniqueId(org.junit.platform.engine.UniqueId) HashSet(java.util.HashSet) PrioritizableTest(com.teamscale.client.PrioritizableTest)

Example 4 with PrioritizableTest

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

the class TestwiseCoverageAgentTest method shouldHandleMissingRequestBodyForTestrunStartGracefully.

@Test
public void shouldHandleMissingRequestBodyForTestrunStartGracefully() throws Exception {
    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));
    int port = PORT_COUNTER.incrementAndGet();
    new TestwiseCoverageAgent(mockOptions(port), null, reportGenerator);
    ITestwiseCoverageAgentApiWithoutBody api = new Retrofit.Builder().addConverterFactory(MoshiConverterFactory.create()).baseUrl("http://localhost:" + port).build().create(ITestwiseCoverageAgentApiWithoutBody.class);
    Response<List<PrioritizableTestCluster>> response = api.testRunStarted(false, null).execute();
    assertThat(response.isSuccessful()).describedAs(response.toString()).isTrue();
    List<PrioritizableTestCluster> tests = response.body();
    assertThat(tests).isNotNull().hasSize(1);
    assertThat(tests.get(0).tests).hasSize(1);
}
Also used : PrioritizableTestCluster(com.teamscale.client.PrioritizableTestCluster) List(java.util.List) PrioritizableTest(com.teamscale.client.PrioritizableTest) PrioritizableTest(com.teamscale.client.PrioritizableTest) Test(org.junit.jupiter.api.Test) RunningTest(com.teamscale.tia.client.RunningTest)

Aggregations

PrioritizableTest (com.teamscale.client.PrioritizableTest)4 ClusteredTestDetails (com.teamscale.client.ClusteredTestDetails)3 PrioritizableTestCluster (com.teamscale.client.PrioritizableTestCluster)3 Test (org.junit.jupiter.api.Test)3 AgentOptions (com.teamscale.jacoco.agent.options.AgentOptions)2 RunningTest (com.teamscale.tia.client.RunningTest)2 File (java.io.File)2 List (java.util.List)2 StringUtils (com.teamscale.client.StringUtils)1 TestDetails (com.teamscale.client.TestDetails)1 JacocoRuntimeController (com.teamscale.jacoco.agent.JacocoRuntimeController)1 TestExecution (com.teamscale.report.testwise.model.TestExecution)1 TestwiseCoverage (com.teamscale.report.testwise.model.TestwiseCoverage)1 ImpactedTestEngine (com.teamscale.test_impacted.engine.ImpactedTestEngine)1 TestRun (com.teamscale.tia.client.TestRun)1 TestRunWithClusteredSuggestions (com.teamscale.tia.client.TestRunWithClusteredSuggestions)1 TiaAgent (com.teamscale.tia.client.TiaAgent)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 HashMap (java.util.HashMap)1