Skip to content

Commit

Permalink
TS-38628 Migrate cucumber-maven-tia
Browse files Browse the repository at this point in the history
  • Loading branch information
Avanatiker committed Jan 31, 2025
1 parent 4eea509 commit 1d237e6
Show file tree
Hide file tree
Showing 3 changed files with 100 additions and 82 deletions.
1 change: 1 addition & 0 deletions system-tests/cucumber-maven-tia/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
plugins {
com.teamscale.`kotlin-convention`
com.teamscale.`system-test-convention`
com.teamscale.coverage
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
@@ -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<String> { it.uniformPath }
.containsExactlyInAnyOrder(*IMPACTED_TEST_PATHS)
},
Executable {
// Verify that all test results are PASSED
assertThat(unitTestReport?.tests)
.extracting<ETestExecutionResult> { it.result }
.containsExactlyInAnyOrder(*IMPACTED_TEST_PATHS.map { ETestExecutionResult.PASSED }.toTypedArray())
},
Executable {
// Ensure coverage strings match the expected values
assertThat(unitTestReport?.tests)
.extracting<String> { getCoverageString(it) }
.containsExactly(
COVERAGE_ADD,
COVERAGE_ADD,
COVERAGE_ADD,
COVERAGE_ADD,
COVERAGE_ADD,
COVERAGE_SUBTRACT
)
}
)

Check warning on line 82 in system-tests/cucumber-maven-tia/src/test/kotlin/com/teamscale/tia/TiaMavenCucumberSystemTest.kt

View check run for this annotation

cqse.teamscale.io / teamscale-findings

system-tests/cucumber-maven-tia/src/test/kotlin/com/teamscale/tia/TiaMavenCucumberSystemTest.kt#L41-L82

Violation of method length threshold (source lines of code) of 30: 32 https://cqse.teamscale.io/findings/details/teamscale-jacoco-agent?t=ts%2F38628_iterative_kotlin_migration_system_tests%3AHEAD&id=A4100E7C14A660C5D08513CAEB16040A
}


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"
}
}

0 comments on commit 1d237e6

Please sign in to comment.