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