Skip to content

Commit b4ead56

Browse files
committed
Add unit tests to verify disabled Jacoco integration
1 parent 7dffa06 commit b4ead56

File tree

1 file changed

+48
-4
lines changed

1 file changed

+48
-4
lines changed

plugin/android-junit5/src/test/kotlin/de/mannodermaus/gradle/plugins/junit5/plugin/AgpJacocoVariantTests.kt

+48-4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import de.mannodermaus.gradle.plugins.junit5.util.assertAll
1010
import de.mannodermaus.gradle.plugins.junit5.util.evaluate
1111
import de.mannodermaus.gradle.plugins.junit5.util.get
1212
import de.mannodermaus.gradle.plugins.junit5.util.getDependentTaskNames
13+
import org.gradle.testing.jacoco.tasks.JacocoReport
1314
import org.junit.jupiter.api.DynamicTest
1415
import org.junit.jupiter.api.DynamicTest.dynamicTest
1516
import org.junit.jupiter.api.Test
@@ -29,12 +30,55 @@ interface AgpJacocoVariantTests : AgpVariantAwareTests {
2930
project.evaluate()
3031

3132
assertWithMessage("create a child task")
32-
.that(project.tasks.findByName("${JACOCO_TASK_NAME}Staging"))
33-
.isNotNull()
33+
.that(project.tasks.findByName("${JACOCO_TASK_NAME}Staging"))
34+
.isNotNull()
3435

3536
assertWithMessage("connect to parent task")
36-
.that(project.tasks.getByName(JACOCO_TASK_NAME).getDependentTaskNames())
37-
.contains("${JACOCO_TASK_NAME}Staging")
37+
.that(project.tasks.getByName(JACOCO_TASK_NAME).getDependentTaskNames())
38+
.contains("${JACOCO_TASK_NAME}Staging")
39+
}
40+
41+
@TestFactory
42+
fun `do not interfere if task generation is disabled`() = forEachBuildType(
43+
beforeBuild = {
44+
it.applyJacocoPlugin()
45+
},
46+
beforeEvaluate = {
47+
it.junitPlatform.jacocoOptions {
48+
taskGenerationEnabled = false
49+
}
50+
}
51+
) { project, buildType ->
52+
val name = jacocoVariantTaskName(buildType)
53+
54+
assertWithMessage("do not create a child task for build type $buildType")
55+
.that(project.tasks.findByName(name))
56+
.isNull()
57+
}
58+
59+
@TestFactory
60+
fun `do not interfere with custom Jacoco task if task generation is disabled`() = forEachBuildType(
61+
beforeBuild = {
62+
it.applyJacocoPlugin()
63+
},
64+
beforeEvaluate = {
65+
it.tasks.register("jacocoTestReport", JacocoReport::class.java) { task ->
66+
task.group = "TEST MARKER"
67+
}
68+
it.junitPlatform.jacocoOptions {
69+
taskGenerationEnabled = false
70+
}
71+
}
72+
) { project, buildType ->
73+
val name = jacocoVariantTaskName(buildType)
74+
75+
assertWithMessage("do not create a child task for build type $buildType")
76+
.that(project.tasks.findByName(name))
77+
.isNull()
78+
79+
assertWithMessage("do not overwrite the custom task")
80+
.that(project.tasks.getByName("jacocoTestReport").group)
81+
.isEqualTo("TEST MARKER")
3882
}
3983

4084
@TestFactory

0 commit comments

Comments
 (0)