Skip to content

Commit 65b52f3

Browse files
authored
Merge pull request #885 from cqse/ts/46135_coverage_aggregation_test_fail
TS-46135: Fix coverage aggregation skipped when tests fail
2 parents 235acc6 + 9022074 commit 65b52f3

3 files changed

Lines changed: 134 additions & 2 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ We use [semantic versioning](http://semver.org/):
66

77
# Next version
88
- [feature] _agent_: Renamed the docker image to `cqse/teamscale-java-profiler` and added support for the `linux/arm64` platform
9+
- [fix] _teamscale-gradle-plugin_: Coverage aggregation report and upload were skipped when tests failed with `--continue`
910

1011
# 36.4.1
1112
- [fix] _agent_: Fixed `IllegalStateException: Can't add different class with same name` when application servers like JBoss perform a reload without full restart or when duplicate class files exist across multiple archives

teamscale-gradle-plugin/src/main/kotlin/com/teamscale/aggregation/compact/CompactCoverageAggregationPlugin.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,7 @@ abstract class CompactCoverageAggregationPlugin : Plugin<Project> {
5252
attributes.artifactType(ArtifactTypeDefinition.BINARY_DATA_TYPE)
5353
}.files
5454
this.executionData.from(executionData)
55-
dependsOn(executionData.buildDependencies)
5655
this.classDirectories.from(classDirectories)
57-
dependsOn(classDirectories.buildDependencies)
5856
}
5957
}
6058

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
package com.teamscale
2+
3+
import org.assertj.core.api.Assertions.assertThat
4+
import org.gradle.testkit.runner.TaskOutcome
5+
import org.junit.jupiter.api.BeforeEach
6+
import org.junit.jupiter.api.Test
7+
8+
/**
9+
* Tests the compact coverage aggregation plugin across multiple subprojects,
10+
* specifically that the aggregation report is still generated when tests fail with --continue.
11+
*/
12+
class CompactCoverageAggregationTest : TeamscalePluginTestBase() {
13+
14+
@BeforeEach
15+
fun init() {
16+
setupSettings()
17+
setupRootBuildFile()
18+
setupSubprojectMod1()
19+
}
20+
21+
private fun setupSettings() {
22+
rootProject.settingsFile.writeText(
23+
"""
24+
dependencyResolutionManagement {
25+
repositories {
26+
mavenLocal()
27+
mavenCentral()
28+
}
29+
}
30+
31+
include 'mod1'
32+
""".trimIndent()
33+
)
34+
}
35+
36+
private fun setupRootBuildFile() {
37+
rootProject.buildFile.writeText(
38+
"""
39+
import com.teamscale.aggregation.TestSuiteCompatibilityUtil
40+
import com.teamscale.aggregation.compact.AggregateCompactCoverageReport
41+
42+
plugins {
43+
id 'java'
44+
id 'com.teamscale'
45+
id 'com.teamscale.aggregation'
46+
}
47+
48+
teamscale {
49+
commit {
50+
revision = "abcd1337"
51+
}
52+
repository = "myRepoId"
53+
}
54+
55+
dependencies {
56+
reportAggregation(subprojects)
57+
}
58+
59+
reporting {
60+
reports {
61+
unitTestAggregateCompactCoverageReport(AggregateCompactCoverageReport) { testSuiteName = 'unitTest' }
62+
}
63+
}
64+
65+
subprojects {
66+
apply plugin: 'com.teamscale'
67+
68+
tasks.register('runUnitTests', Test) {
69+
useJUnitPlatform()
70+
testClassesDirs = sourceSets.test.output.classesDirs
71+
classpath = sourceSets.test.runtimeClasspath
72+
}
73+
TestSuiteCompatibilityUtil.exposeTestForAggregation(tasks.named('runUnitTests'), 'unitTest')
74+
}
75+
""".trimIndent()
76+
)
77+
}
78+
79+
private fun setupSubprojectMod1() {
80+
java.io.File(rootProject.dir("mod1"), "build.gradle").writeText(
81+
"""
82+
plugins {
83+
id 'java'
84+
}
85+
86+
dependencies {
87+
testImplementation(platform("org.junit:junit-bom:5.12.0"))
88+
testImplementation("org.junit.jupiter:junit-jupiter")
89+
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
90+
}
91+
""".trimIndent()
92+
)
93+
94+
rootProject.file("mod1/src/main/java/com/example/Lib.java").writeText(
95+
"""
96+
package com.example;
97+
98+
public class Lib {
99+
public static int add(int a, int b) {
100+
return a + b;
101+
}
102+
}
103+
""".trimIndent()
104+
)
105+
106+
rootProject.file("mod1/src/test/java/com/example/LibTest.java").writeText(
107+
"""
108+
package com.example;
109+
110+
import org.junit.jupiter.api.Test;
111+
import static org.junit.jupiter.api.Assertions.assertEquals;
112+
113+
class LibTest {
114+
@Test
115+
void failingTest() {
116+
assertEquals(3, Lib.add(1, 2));
117+
throw new RuntimeException("intentional failure");
118+
}
119+
}
120+
""".trimIndent()
121+
)
122+
}
123+
124+
@Test
125+
fun `compact coverage aggregation runs despite test failure with --continue`() {
126+
val build = runExpectingError("--continue", "clean", "unitTestAggregateCompactCoverageReport")
127+
128+
assertThat(build.task(":mod1:runUnitTests")?.outcome)
129+
.isEqualTo(TaskOutcome.FAILED)
130+
assertThat(build.task(":unitTestAggregateCompactCoverageReport")?.outcome)
131+
.isEqualTo(TaskOutcome.SUCCESS)
132+
}
133+
}

0 commit comments

Comments
 (0)