From 1d237e6a158845c32da5ba9574b9d2c7f63c0cd1 Mon Sep 17 00:00:00 2001 From: Constructor Date: Fri, 31 Jan 2025 03:23:41 +0100 Subject: [PATCH] TS-38628 Migrate cucumber-maven-tia --- .../cucumber-maven-tia/build.gradle.kts | 1 + .../tia/TiaMavenCucumberSystemTest.java | 82 --------------- .../tia/TiaMavenCucumberSystemTest.kt | 99 +++++++++++++++++++ 3 files changed, 100 insertions(+), 82 deletions(-) delete mode 100644 system-tests/cucumber-maven-tia/src/test/java/com/teamscale/tia/TiaMavenCucumberSystemTest.java create mode 100644 system-tests/cucumber-maven-tia/src/test/kotlin/com/teamscale/tia/TiaMavenCucumberSystemTest.kt diff --git a/system-tests/cucumber-maven-tia/build.gradle.kts b/system-tests/cucumber-maven-tia/build.gradle.kts index 10a3c21f0..708306ce3 100644 --- a/system-tests/cucumber-maven-tia/build.gradle.kts +++ b/system-tests/cucumber-maven-tia/build.gradle.kts @@ -1,4 +1,5 @@ plugins { + com.teamscale.`kotlin-convention` com.teamscale.`system-test-convention` com.teamscale.coverage } diff --git a/system-tests/cucumber-maven-tia/src/test/java/com/teamscale/tia/TiaMavenCucumberSystemTest.java b/system-tests/cucumber-maven-tia/src/test/java/com/teamscale/tia/TiaMavenCucumberSystemTest.java deleted file mode 100644 index 17952e61c..000000000 --- a/system-tests/cucumber-maven-tia/src/test/java/com/teamscale/tia/TiaMavenCucumberSystemTest.java +++ /dev/null @@ -1,82 +0,0 @@ -package com.teamscale.tia; - -import com.teamscale.report.testwise.model.ETestExecutionResult; -import com.teamscale.report.testwise.model.TestwiseCoverageReport; -import com.teamscale.test.commons.SystemTestUtils; -import com.teamscale.test.commons.TeamscaleMockServer; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -import java.util.Arrays; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertAll; - -/** - * Runs several Maven projects' Surefire tests that have the agent attached and one of our JUnit run listeners enabled. - * Checks that this produces a correct coverage report. - */ -public class TiaMavenCucumberSystemTest { - - private static TeamscaleMockServer teamscaleMockServer = null; - - private static final String[] IMPACTED_TEST_PATHS = { // sorted alphabetically - "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Actually we just want to test a http:\\/\\/link #1", // also tests addition, escaped / - "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Add two numbers #1", - "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Add two numbers #2", - "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Add two numbers #3", - "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Add two numbers #4", - "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Subtract two numbers 99 & 99 #1" - }; - - private static final String COVERAGE_ADD = "Calculator.java:3,5;StepDefinitions.java:12,24-25,29-30,39-40"; - private static final String COVERAGE_SUBTRACT = "Calculator.java:3,9;StepDefinitions.java:12,24-25,34-35,39-40"; - - @BeforeEach - public void startFakeTeamscaleServer() throws Exception { - if (teamscaleMockServer == null) { - teamscaleMockServer = new TeamscaleMockServer(SystemTestUtils.TEAMSCALE_PORT) - .acceptingReportUploads() - .withImpactedTests(IMPACTED_TEST_PATHS); - } - teamscaleMockServer.uploadedReports.clear(); - } - - @AfterEach - public void stopFakeTeamscaleServer() { - teamscaleMockServer.shutdown(); - } - - @Test - public void testMavenTia() throws Exception { - SystemTestUtils.runMavenTests("maven-project"); - - assertThat(teamscaleMockServer.availableTests).extracting("partition").contains("MyPartition"); - - assertThat(teamscaleMockServer.uploadedReports).hasSize(1); - - TestwiseCoverageReport unitTestReport = teamscaleMockServer.parseUploadedTestwiseCoverageReport(0); - assertThat(unitTestReport.tests).hasSize(IMPACTED_TEST_PATHS.length); - assertThat(unitTestReport.partial).isTrue(); - assertAll(() -> { - assertThat(unitTestReport.tests) - .extracting(test -> test.uniformPath) - .containsExactlyInAnyOrder(IMPACTED_TEST_PATHS); - assertThat(unitTestReport.tests) - .extracting(test -> test.result) - .containsExactlyInAnyOrder(Arrays.stream(IMPACTED_TEST_PATHS) - .map(s -> ETestExecutionResult.PASSED) - .toArray(ETestExecutionResult[]::new)); - assertThat(unitTestReport.tests) - .extracting(SystemTestUtils::getCoverageString) - .containsExactly(COVERAGE_ADD, // must match TEST_PATHS - COVERAGE_ADD, - COVERAGE_ADD, - COVERAGE_ADD, - COVERAGE_ADD, - COVERAGE_SUBTRACT); - }); - } - -} diff --git a/system-tests/cucumber-maven-tia/src/test/kotlin/com/teamscale/tia/TiaMavenCucumberSystemTest.kt b/system-tests/cucumber-maven-tia/src/test/kotlin/com/teamscale/tia/TiaMavenCucumberSystemTest.kt new file mode 100644 index 000000000..6ac08bd0e --- /dev/null +++ b/system-tests/cucumber-maven-tia/src/test/kotlin/com/teamscale/tia/TiaMavenCucumberSystemTest.kt @@ -0,0 +1,99 @@ +package com.teamscale.tia + +import com.teamscale.report.testwise.model.ETestExecutionResult +import com.teamscale.test.commons.SystemTestUtils +import com.teamscale.test.commons.SystemTestUtils.getCoverageString +import com.teamscale.test.commons.SystemTestUtils.runMavenTests +import com.teamscale.test.commons.TeamscaleMockServer +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.AfterEach +import org.junit.jupiter.api.Assertions.assertAll +import org.junit.jupiter.api.BeforeEach +import org.junit.jupiter.api.Test +import org.junit.jupiter.api.function.Executable +import java.util.* + +/** + * Runs several Maven projects' Surefire tests that have the agent attached, and one of our JUnit run listeners enabled. + * Checks that this produces a correct coverage report. + */ +class TiaMavenCucumberSystemTest { + private var teamscaleMockServer: TeamscaleMockServer? = null + + @BeforeEach + @Throws(Exception::class) + fun startFakeTeamscaleServer() { + teamscaleMockServer?.uploadedReports?.clear() ?: run { + teamscaleMockServer = TeamscaleMockServer(SystemTestUtils.TEAMSCALE_PORT) + .acceptingReportUploads() + .withImpactedTests(*IMPACTED_TEST_PATHS) + } + } + + @AfterEach + fun stopFakeTeamscaleServer() { + teamscaleMockServer?.shutdown() + } + + @Test + @Throws(Exception::class) + fun testMavenTia() { + runMavenTests("maven-project") + + // Check that the partition is correctly recognized + assertThat(teamscaleMockServer?.availableTests) + .extracting("partition") + .contains("MyPartition") + + // Expect a single report upload + assertThat(teamscaleMockServer?.uploadedReports).hasSize(1) + + val unitTestReport = teamscaleMockServer?.parseUploadedTestwiseCoverageReport(0) + assertThat(unitTestReport?.tests).hasSize(IMPACTED_TEST_PATHS.size) + assertThat(unitTestReport?.partial).isTrue() + + // Bundle checks in assertAll to gather all assertions + assertAll( + Executable { + // Check uniform paths in any order + assertThat(unitTestReport?.tests) + .extracting { it.uniformPath } + .containsExactlyInAnyOrder(*IMPACTED_TEST_PATHS) + }, + Executable { + // Verify that all test results are PASSED + assertThat(unitTestReport?.tests) + .extracting { it.result } + .containsExactlyInAnyOrder(*IMPACTED_TEST_PATHS.map { ETestExecutionResult.PASSED }.toTypedArray()) + }, + Executable { + // Ensure coverage strings match the expected values + assertThat(unitTestReport?.tests) + .extracting { getCoverageString(it) } + .containsExactly( + COVERAGE_ADD, + COVERAGE_ADD, + COVERAGE_ADD, + COVERAGE_ADD, + COVERAGE_ADD, + COVERAGE_SUBTRACT + ) + } + ) + } + + + companion object { + private val IMPACTED_TEST_PATHS = arrayOf( // sorted alphabetically + "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Actually we just want to test a http:\\/\\/link #1", // also tests addition, escaped / + "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Add two numbers #1", + "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Add two numbers #2", + "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Add two numbers #3", + "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Add two numbers #4", + "hellocucumber/RunCucumberTest/hellocucumber/calculator.feature/Subtract two numbers 99 & 99 #1" + ) + + private const val COVERAGE_ADD = "Calculator.java:3,5;StepDefinitions.java:12,24-25,29-30,39-40" + private const val COVERAGE_SUBTRACT = "Calculator.java:3,9;StepDefinitions.java:12,24-25,34-35,39-40" + } +}