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+ }
0 commit comments