Skip to content

Commit f015e47

Browse files
committed
TS-38628 Missing test fixed
1 parent f5dc524 commit f015e47

2 files changed

Lines changed: 77 additions & 63 deletions

File tree

system-tests/junit-run-listener-test/src/test/java/com/teamscale/tia/client/JUnitRunListenerSystemTest.java

Lines changed: 0 additions & 63 deletions
This file was deleted.
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
package com.teamscale.tia.client
2+
3+
import com.teamscale.report.testwise.model.ETestExecutionResult
4+
import com.teamscale.report.testwise.model.TestInfo
5+
import com.teamscale.report.testwise.model.TestwiseCoverageReport
6+
import com.teamscale.test.commons.SystemTestUtils
7+
import com.teamscale.test.commons.SystemTestUtils.coverage
8+
import com.teamscale.test.commons.SystemTestUtils.runMavenTests
9+
import com.teamscale.test.commons.TeamscaleMockServer
10+
import org.assertj.core.api.Assertions
11+
import org.assertj.core.api.Assertions.assertThat
12+
import org.assertj.core.api.iterable.ThrowingExtractor
13+
import org.junit.jupiter.api.BeforeEach
14+
import org.junit.jupiter.api.Test
15+
import org.junit.jupiter.api.assertAll
16+
import org.junit.jupiter.api.function.Executable
17+
18+
/**
19+
* Runs several Maven projects' Surefire tests that have the agent attached and one of our JUnit run listeners enabled.
20+
* Checks that this produces a correct coverage report.
21+
*/
22+
class JUnitRunListenerSystemTest {
23+
@BeforeEach
24+
@Throws(Exception::class)
25+
fun startFakeTeamscaleServer() {
26+
if (teamscaleMockServer == null) {
27+
teamscaleMockServer = TeamscaleMockServer(SystemTestUtils.TEAMSCALE_PORT).acceptingReportUploads()
28+
}
29+
teamscaleMockServer?.reset()
30+
}
31+
32+
/** Tests the JUnit 5 TestExecutionListener. */
33+
@Test
34+
@Throws(Exception::class)
35+
fun testJUnit5TestExecutionListener() {
36+
runMavenTests("junit5-maven-project")
37+
38+
val report: TestwiseCoverageReport = teamscaleMockServer!!.getOnlyTestwiseCoverageReport("part")
39+
assertThat(report.tests).hasSize(2)
40+
assertAll({
41+
assertThat(report.tests)
42+
.extracting<String> { it.uniformPath }
43+
.containsExactlyInAnyOrder("JUnit4ExecutedWithJUnit5Test/testAdd()", "JUnit5Test/testAdd()")
44+
assertThat(report.tests)
45+
.extracting<ETestExecutionResult> { it.result }
46+
.containsExactlyInAnyOrder(ETestExecutionResult.PASSED, ETestExecutionResult.PASSED)
47+
assertThat(report.tests)
48+
.extracting<String> { it.coverage }
49+
.containsExactly("SystemUnderTest.java:3,6", "SystemUnderTest.java:3,6")
50+
})
51+
}
52+
53+
/** Tests the JUnit 4 RunListener. */
54+
@Test
55+
@Throws(Exception::class)
56+
fun testJUnit4RunListener() {
57+
runMavenTests("junit4-maven-project")
58+
59+
val report = teamscaleMockServer!!.getOnlyTestwiseCoverageReport("part")
60+
assertThat(report.tests).hasSize(1)
61+
assertAll({
62+
Assertions.assertThat(report.tests)
63+
.extracting<String> { it.uniformPath }
64+
.containsExactlyInAnyOrder("JUnit4Test/testAdd")
65+
Assertions.assertThat(report.tests)
66+
.extracting<ETestExecutionResult> { it.result }
67+
.containsExactlyInAnyOrder(ETestExecutionResult.PASSED)
68+
Assertions.assertThat(report.tests)
69+
.extracting<String> { it.coverage }
70+
.containsExactly("SystemUnderTest.java:3,6")
71+
})
72+
}
73+
74+
companion object {
75+
private var teamscaleMockServer: TeamscaleMockServer? = null
76+
}
77+
}

0 commit comments

Comments
 (0)