@@ -5,6 +5,7 @@ import de.mannodermaus.Libraries
5
5
import de.mannodermaus.gradle.plugins.junit5.internal.config.ANDROID_JUNIT5_RUNNER_BUILDER_CLASS
6
6
import de.mannodermaus.gradle.plugins.junit5.internal.extensions.android
7
7
import de.mannodermaus.gradle.plugins.junit5.internal.extensions.junitPlatform
8
+ import de.mannodermaus.gradle.plugins.junit5.util.assertThat
8
9
import de.mannodermaus.gradle.plugins.junit5.util.evaluate
9
10
import org.gradle.api.Project
10
11
import org.junit.jupiter.api.BeforeEach
@@ -67,14 +68,15 @@ class InstrumentationSupportTests {
67
68
/* Dependencies */
68
69
69
70
@Test
70
- fun `add the dependencies` () {
71
+ fun `add only the main dependencies` () {
71
72
project.addJUnitJupiterApi()
72
73
project.evaluate()
73
74
74
- assertThat(project.dependencyNamed(" androidTestImplementation" , " android-test-core" ))
75
- .isEqualTo(" ${Libraries .instrumentationCore} :${Libraries .instrumentationVersion} " )
76
- assertThat(project.dependencyNamed(" androidTestRuntimeOnly" , " android-test-runner" ))
77
- .isEqualTo(" ${Libraries .instrumentationRunner} :${Libraries .instrumentationVersion} " )
75
+ assertThat(project).configuration(" androidTestImplementation" ).hasDependency(coreLibrary())
76
+ assertThat(project).configuration(" androidTestRuntimeOnly" ).hasDependency(runnerLibrary())
77
+
78
+ assertThat(project).configuration(" androidTestImplementation" ).doesNotHaveDependency(extensionsLibrary())
79
+ assertThat(project).configuration(" androidTestImplementation" ).doesNotHaveDependency(composeLibrary())
78
80
}
79
81
80
82
@Test
@@ -83,8 +85,8 @@ class InstrumentationSupportTests {
83
85
project.junitPlatform.instrumentationTests.version.set(" 1.3.3.7" )
84
86
project.evaluate()
85
87
86
- assertThat(project.dependencyNamed (" androidTestImplementation" , " android-test-core " )).endsWith( " 1.3.3.7" )
87
- assertThat(project.dependencyNamed (" androidTestRuntimeOnly" , " android-test-runner " )).endsWith( " 1.3.3.7" )
88
+ assertThat(project).configuration (" androidTestImplementation" ).hasDependency(coreLibrary( " 1.3.3.7" ) )
89
+ assertThat(project).configuration (" androidTestRuntimeOnly" ).hasDependency(runnerLibrary( " 1.3.3.7" ) )
88
90
}
89
91
90
92
@Test
@@ -96,8 +98,8 @@ class InstrumentationSupportTests {
96
98
project.dependencies.add(" androidTestRuntimeOnly" , addedRunner)
97
99
project.evaluate()
98
100
99
- assertThat(project.dependencyNamed (" androidTestImplementation" , " android-test-core " )).isEqualTo(addedCore )
100
- assertThat(project.dependencyNamed (" androidTestRuntimeOnly" , " android-test-runner " )).isEqualTo(addedRunner )
101
+ assertThat(project).configuration (" androidTestImplementation" ).hasDependency(coreLibrary( " 0.1.3.3.7 " ) )
102
+ assertThat(project).configuration (" androidTestRuntimeOnly" ).hasDependency(runnerLibrary( " 0.1.3.3.7 " ) )
101
103
}
102
104
103
105
@Test
@@ -106,16 +108,61 @@ class InstrumentationSupportTests {
106
108
project.junitPlatform.instrumentationTests.enabled.set(false )
107
109
project.evaluate()
108
110
109
- assertThat(project.dependencyNamed (" androidTestImplementation" , " android-test-core " )).isNull( )
110
- assertThat(project.dependencyNamed (" androidTestRuntimeOnly" , " android-test-runner " )).isNull( )
111
+ assertThat(project).configuration (" androidTestImplementation" ).doesNotHaveDependency(coreLibrary( null ) )
112
+ assertThat(project).configuration (" androidTestRuntimeOnly" ).doesNotHaveDependency(runnerLibrary( null ) )
111
113
}
112
114
113
115
@Test
114
116
fun `do not add the dependencies when Jupiter is not added` () {
115
117
project.evaluate()
116
118
117
- assertThat(project.dependencyNamed(" androidTestImplementation" , " android-test-core" )).isNull()
118
- assertThat(project.dependencyNamed(" androidTestRuntimeOnly" , " android-test-runner" )).isNull()
119
+ assertThat(project).configuration(" androidTestImplementation" ).doesNotHaveDependency(coreLibrary(null ))
120
+ assertThat(project).configuration(" androidTestRuntimeOnly" ).doesNotHaveDependency(runnerLibrary(null ))
121
+ }
122
+
123
+ @Test
124
+ fun `do not add the dependencies when Jupiter is not added, even if extension is configured to be added` () {
125
+ project.junitPlatform.instrumentationTests.includeExtensions.set(true )
126
+ project.evaluate()
127
+
128
+ assertThat(project).configuration(" androidTestImplementation" ).doesNotHaveDependency(coreLibrary(null ))
129
+ assertThat(project).configuration(" androidTestImplementation" ).doesNotHaveDependency(extensionsLibrary(null ))
130
+ assertThat(project).configuration(" androidTestRuntimeOnly" ).doesNotHaveDependency(runnerLibrary(null ))
131
+ }
132
+
133
+ @Test
134
+ fun `add the extension library if configured` () {
135
+ project.addJUnitJupiterApi()
136
+ project.junitPlatform.instrumentationTests.includeExtensions.set(true )
137
+ project.evaluate()
138
+
139
+ assertThat(project).configuration(" androidTestImplementation" ).hasDependency(coreLibrary())
140
+ assertThat(project).configuration(" androidTestImplementation" ).hasDependency(extensionsLibrary())
141
+ assertThat(project).configuration(" androidTestRuntimeOnly" ).hasDependency(runnerLibrary())
142
+ }
143
+
144
+ @Test
145
+ fun `add the compose library if configured` () {
146
+ project.addJUnitJupiterApi()
147
+ project.addCompose()
148
+ project.evaluate()
149
+
150
+ assertThat(project).configuration(" androidTestImplementation" ).hasDependency(coreLibrary())
151
+ assertThat(project).configuration(" androidTestImplementation" ).hasDependency(composeLibrary())
152
+ assertThat(project).configuration(" androidTestRuntimeOnly" ).hasDependency(runnerLibrary())
153
+ }
154
+
155
+ @Test
156
+ fun `add the extensions and compose libraries if configured` () {
157
+ project.addJUnitJupiterApi()
158
+ project.addCompose()
159
+ project.junitPlatform.instrumentationTests.includeExtensions.set(true )
160
+ project.evaluate()
161
+
162
+ assertThat(project).configuration(" androidTestImplementation" ).hasDependency(coreLibrary())
163
+ assertThat(project).configuration(" androidTestImplementation" ).hasDependency(composeLibrary())
164
+ assertThat(project).configuration(" androidTestImplementation" ).hasDependency(extensionsLibrary())
165
+ assertThat(project).configuration(" androidTestRuntimeOnly" ).hasDependency(runnerLibrary())
119
166
}
120
167
121
168
/* Private */
@@ -124,10 +171,27 @@ class InstrumentationSupportTests {
124
171
dependencies.add(" androidTestImplementation" , " org.junit.jupiter:junit-jupiter-api:+" )
125
172
}
126
173
127
- private fun Project.dependencyNamed (configurationName : String , name : String ): String? {
128
- return configurations.getByName(configurationName)
129
- .dependencies
130
- .firstOrNull { it.name == name }
131
- ?.run { " $group :$name :$version " }
174
+ private fun Project.addCompose () {
175
+ dependencies.add(" androidTestImplementation" , " androidx.compose.ui:ui-test-android:+" )
176
+ }
177
+
178
+ private fun composeLibrary (withVersion : String? = Libraries .instrumentationVersion) =
179
+ library(Libraries .instrumentationCompose, withVersion)
180
+
181
+ private fun coreLibrary (withVersion : String? = Libraries .instrumentationVersion) =
182
+ library(Libraries .instrumentationCore, withVersion)
183
+
184
+ private fun extensionsLibrary (withVersion : String? = Libraries .instrumentationVersion) =
185
+ library(Libraries .instrumentationExtensions, withVersion)
186
+
187
+ private fun runnerLibrary (withVersion : String? = Libraries .instrumentationVersion) =
188
+ library(Libraries .instrumentationRunner, withVersion)
189
+
190
+ private fun library (artifactId : String , version : String? ) = buildString {
191
+ append(artifactId)
192
+ if (version != null ) {
193
+ append(' :' )
194
+ append(version)
195
+ }
132
196
}
133
197
}
0 commit comments