Skip to content

Commit e2880b2

Browse files
author
Marcel Schnelle
authored
Introduce variant-aware filters (#100)
* Implement auto-replacing & merging include/exclude rules for filter DSL * Add DSL extension points for filters applied only to certain build variants * Add a few more unit tests to validate Groovy support for dynamic filters() DSL
1 parent f4c70ed commit e2880b2

File tree

12 files changed

+919
-108
lines changed

12 files changed

+919
-108
lines changed

android-junit5-tests/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ dependencies {
7777
testImplementation "junit:junit:$JUNIT4_VERSION"
7878
testImplementation "org.junit.jupiter:junit-jupiter-api:$JUNIT_JUPITER_VERSION"
7979
testImplementation "org.junit.jupiter:junit-jupiter-params:$JUNIT_JUPITER_VERSION"
80-
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$JUNIT_JUPITER_VERSION"
80+
testImplementation "org.junit.jupiter:junit-jupiter-engine:$JUNIT_JUPITER_VERSION"
8181
testImplementation "org.jetbrains.spek:spek-api:$SPEK_VERSION"
8282
testRuntimeOnly "org.jetbrains.spek:spek-junit-platform-engine:$SPEK_VERSION"
8383
testImplementation "org.junit-pioneer:junit-pioneer:$JUNIT_PIONEER_VERSION"
Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
package de.mannodermaus.gradle.plugins.junit5
2+
3+
import de.mannodermaus.gradle.plugins.junit5.tasks.JUnit5Task
4+
import de.mannodermaus.gradle.plugins.junit5.util.TestEnvironment
5+
import de.mannodermaus.gradle.plugins.junit5.util.TestProjectFactory
6+
import kotlin.io.FilesKt
7+
import org.gradle.api.Project
8+
import org.junit.jupiter.api.AfterEach
9+
import org.junit.jupiter.api.BeforeEach
10+
import org.junit.jupiter.api.DisplayName
11+
import org.junit.jupiter.api.Test
12+
13+
import static org.assertj.core.api.Assertions.assertThat
14+
15+
class DslGroovyTests {
16+
17+
private TestProjectFactory factory
18+
private Project testRoot
19+
20+
@BeforeEach
21+
void beforeEach() {
22+
def environment = new TestEnvironment()
23+
24+
this.factory = new TestProjectFactory(environment)
25+
this.testRoot = factory.newRootProject()
26+
}
27+
28+
@AfterEach
29+
void afterEach() {
30+
FilesKt.deleteRecursively(this.testRoot.rootDir)
31+
}
32+
33+
@Test
34+
@DisplayName("dynamic filters methods can be called on existing build types")
35+
void dynamicFiltersMethodsCanBeCalledOnExistingBuildTypes() {
36+
def project = factory.newProject(testRoot)
37+
.asAndroidApplication()
38+
.build()
39+
40+
project.android.testOptions.junitPlatform {
41+
filters {
42+
tags {
43+
include "some-tag"
44+
exclude "other-tag"
45+
}
46+
}
47+
debugFilters {
48+
tags {
49+
include "debug-tag"
50+
}
51+
}
52+
}
53+
54+
project.evaluate()
55+
56+
def debugTask = project.tasks.getByName("junitPlatformTestDebug") as JUnit5Task
57+
assertThat(debugTask.tagIncludes).containsOnly("some-tag", "debug-tag")
58+
assertThat(debugTask.tagExcludes).containsOnly("other-tag")
59+
60+
def releaseTask = project.tasks.getByName("junitPlatformTestRelease") as JUnit5Task
61+
assertThat(releaseTask.tagIncludes).containsOnly("some-tag")
62+
assertThat(releaseTask.tagExcludes).containsOnly("other-tag")
63+
}
64+
65+
@Test
66+
@DisplayName("dynamic filters methods can be called on existing product flavors")
67+
void dynamicFiltersMethodsCanBeCalledOnExistingProductFlavors() {
68+
def project = factory.newProject(testRoot)
69+
.asAndroidApplication()
70+
.build()
71+
72+
project.android {
73+
flavorDimensions "tier"
74+
productFlavors {
75+
free {
76+
dimension "tier"
77+
}
78+
paid {
79+
dimension "tier"
80+
}
81+
}
82+
83+
testOptions.junitPlatform {
84+
filters {
85+
tags {
86+
include "some-tag"
87+
exclude "other-tag"
88+
}
89+
}
90+
freeDebugFilters {
91+
tags {
92+
include "free-debug-tag"
93+
}
94+
}
95+
paidFilters {
96+
tags {
97+
include "paid-tag"
98+
}
99+
}
100+
releaseFilters {
101+
tags {
102+
include "release-tag"
103+
}
104+
}
105+
}
106+
}
107+
108+
project.evaluate()
109+
110+
def freeDebugTask = project.tasks.getByName("junitPlatformTestFreeDebug") as JUnit5Task
111+
assertThat(freeDebugTask.tagIncludes).containsOnly("some-tag", "free-debug-tag")
112+
assertThat(freeDebugTask.tagExcludes).containsOnly("other-tag")
113+
114+
def freeReleaseTask = project.tasks.getByName("junitPlatformTestFreeRelease") as JUnit5Task
115+
assertThat(freeReleaseTask.tagIncludes).containsOnly("some-tag", "release-tag")
116+
assertThat(freeReleaseTask.tagExcludes).containsOnly("other-tag")
117+
118+
def paidDebugTask = project.tasks.getByName("junitPlatformTestPaidDebug") as JUnit5Task
119+
assertThat(paidDebugTask.tagIncludes).containsOnly("some-tag", "paid-tag")
120+
assertThat(paidDebugTask.tagExcludes).containsOnly("other-tag")
121+
122+
def paidReleaseTask = project.tasks.getByName("junitPlatformTestPaidRelease") as JUnit5Task
123+
assertThat(paidReleaseTask.tagIncludes).containsOnly("some-tag", "paid-tag", "release-tag")
124+
assertThat(paidReleaseTask.tagExcludes).containsOnly("other-tag")
125+
}
126+
}

android-junit5-tests/src/test/groovy/de/mannodermaus/gradle/plugins/junit5/util/TaskUtils.groovy

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)