@@ -13,11 +13,6 @@ however, that it is recommended to use IDEA 2017.3 or newer since more recent ve
13
13
IDEA download the following JARs automatically based on the API version used in the
14
14
project: `junit-platform-launcher`, `junit-jupiter-engine`, and `junit-vintage-engine`.
15
15
16
- WARNING: IntelliJ IDEA releases prior to IDEA 2017.3 bundle specific versions of JUnit 5.
17
- Thus, if you want to use a newer version of JUnit Jupiter, execution of tests within the
18
- IDE might fail due to version conflicts. In such cases, please follow the instructions
19
- below to use a newer version of JUnit 5 than the one bundled with IntelliJ IDEA.
20
-
21
16
In order to use a different JUnit 5 version (e.g., {jupiter-version}), you may need to
22
17
include the corresponding versions of the `junit-platform-launcher`,
23
18
`junit-jupiter-engine`, and `junit-vintage-engine` JARs in the classpath.
@@ -27,9 +22,7 @@ include the corresponding versions of the `junit-platform-launcher`,
27
22
[subs=attributes+]
28
23
----
29
24
testImplementation(platform("org.junit:junit-bom:{bom-version}"))
30
- testRuntimeOnly("org.junit.platform:junit-platform-launcher") {
31
- because("Only needed to run tests in a version of IntelliJ IDEA that bundles older versions")
32
- }
25
+ testRuntimeOnly("org.junit.platform:junit-platform-launcher")
33
26
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
34
27
testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
35
28
----
@@ -40,7 +33,6 @@ testRuntimeOnly("org.junit.vintage:junit-vintage-engine")
40
33
----
41
34
<!-- ... -->
42
35
<dependencies>
43
- <!-- Only needed to run tests in a version of IntelliJ IDEA that bundles older versions -->
44
36
<dependency>
45
37
<groupId>org.junit.platform</groupId>
46
38
<artifactId>junit-platform-launcher</artifactId>
@@ -150,48 +142,63 @@ test {
150
142
----
151
143
152
144
Please refer to the
153
- https://docs.gradle.org/current/userguide/java_plugin .html#sec:java_test [official Gradle documentation]
145
+ https://docs.gradle.org/current/userguide/java_testing .html[official Gradle documentation]
154
146
for a comprehensive list of options.
155
147
156
148
[[running-tests-build-gradle-bom]]
157
149
===== Aligning dependency versions
158
150
151
+ TIP: See <<running-tests-build-spring-boot>> for details on how to override the version
152
+ of JUnit used in your Spring Boot application.
153
+
159
154
Unless you're using Spring Boot which defines its own way of managing dependencies, it is
160
- recommended to use the JUnit Platform BOM to align the versions of all JUnit 5 artifacts.
155
+ recommended to use the JUnit Platform <<dependency-metadata-junit-bom>> to align the
156
+ versions of all JUnit 5 artifacts.
161
157
162
158
[source,groovy,indent=0]
163
159
[subs=attributes+]
160
+ .Explicit platform dependency on the BOM
164
161
----
165
162
dependencies {
166
163
testImplementation(platform("org.junit:junit-bom:{bom-version}"))
164
+ testImplementation("org.junit.jupiter:junit-jupiter")
165
+ testRuntimeOnly("org.junit.platform:junit-platform-launcher")
167
166
}
168
167
----
169
168
170
169
Using the BOM allows you to omit the version when declaring dependencies on all artifacts
171
170
with the `org.junit.platform`, `org.junit.jupiter`, and `org.junit.vintage` group IDs.
172
171
173
- TIP: See <<running-tests-build-spring-boot>> for details on how to override the version
174
- of JUnit used in your Spring Boot application.
175
-
176
- [[running-tests-build-gradle-config-params]]
177
- ===== Configuration Parameters
178
-
179
- The standard Gradle `test` task currently does not provide a dedicated DSL to set JUnit
180
- Platform <<running-tests-config-params, configuration parameters>> to influence test
181
- discovery and execution. However, you can provide configuration parameters within the
182
- build script via system properties (as shown below) or via the
183
- `junit-platform.properties` file.
172
+ Since all JUnit artifacts declare a
173
+ https://docs.gradle.org/current/userguide/platforms.html[platform] dependency on the BOM,
174
+ you usually don't need to declare an explicit dependency on it yourself. Instead, it's
175
+ sufficient to declare _one_ regular dependency that includes a version number. Gradle will
176
+ then pull in the BOM automatically so you can omit the version for all other JUnit 5
177
+ artifacts.
184
178
185
179
[source,groovy,indent=0]
180
+ [subs=attributes+]
181
+ .Implicit platform dependency on the BOM
186
182
----
187
- test {
188
- // ...
189
- systemProperty("junit.jupiter.conditions.deactivate", "*")
190
- systemProperty("junit.jupiter.extensions.autodetection.enabled", true)
191
- systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_class")
192
- // ...
183
+ dependencies {
184
+ testImplementation("org.junit.jupiter:junit-jupiter:{jupiter-version}") // <1>
185
+ testRuntimeOnly("org.junit.platform:junit-platform-launcher") // <2>
193
186
}
194
187
----
188
+ <1> Dependency declaration with explicit version. Pulls in the `junit-bom` automatically.
189
+ <2> Dependency declaration without version. The version is supplied by the `junit-bom`.
190
+
191
+ [WARNING]
192
+ .Declaring a dependency on junit-platform-launcher
193
+ ====
194
+ Even though pre-8.0 versions of Gradle don't require declaring an explicit
195
+ dependency on `junit-platform-launcher`, it is recommended to do so to ensure the versions
196
+ of JUnit artifacts on the test runtime classpath are aligned.
197
+
198
+ Moreover, doing so is recommended and in some cases even required when importing the
199
+ project into an IDE like <<running-tests-ide-eclipse>> or
200
+ <<running-tests-ide-intellij-idea>>.
201
+ ====
195
202
196
203
[[running-tests-build-gradle-engines-configure]]
197
204
===== Configuring Test Engines
@@ -205,7 +212,38 @@ on the dependency-aggregating JUnit Jupiter artifact similar to the following.
205
212
[subs=attributes+]
206
213
----
207
214
dependencies {
208
- testImplementation("org.junit.jupiter:junit-jupiter:{jupiter-version}") // version can be omitted when using the BOM
215
+ testImplementation("org.junit.jupiter:junit-jupiter:{jupiter-version}")
216
+ testRuntimeOnly("org.junit.platform:junit-platform-launcher")
217
+ }
218
+ ----
219
+
220
+ Alternatively, you can use Gradle's
221
+ https://docs.gradle.org/current/userguide/jvm_test_suite_plugin.html[JVM Test Suite]
222
+ support.
223
+
224
+ [source,kotlin,indent=0]
225
+ [subs=attributes+]
226
+ .Kotlin DSL
227
+ ----
228
+ testing {
229
+ suites {
230
+ named<JvmTestSuite>("test") {
231
+ useJUnitJupiter("{jupiter-version}")
232
+ }
233
+ }
234
+ }
235
+ ----
236
+
237
+ [source,groovy,indent=0]
238
+ [subs=attributes+]
239
+ .Groovy DSL
240
+ ----
241
+ testing {
242
+ suites {
243
+ test {
244
+ useJUnitJupiter("{jupiter-version}")
245
+ }
246
+ }
209
247
}
210
248
----
211
249
@@ -218,7 +256,28 @@ implementation similar to the following.
218
256
----
219
257
dependencies {
220
258
testImplementation("junit:junit:{junit4-version}")
221
- testRuntimeOnly("org.junit.vintage:junit-vintage-engine:{vintage-version}") // version can be omitted when using the BOM
259
+ testRuntimeOnly("org.junit.vintage:junit-vintage-engine:{vintage-version}")
260
+ testRuntimeOnly("org.junit.platform:junit-platform-launcher")
261
+ }
262
+ ----
263
+
264
+ [[running-tests-build-gradle-config-params]]
265
+ ===== Configuration Parameters
266
+
267
+ The standard Gradle `test` task currently does not provide a dedicated DSL to set JUnit
268
+ Platform <<running-tests-config-params, configuration parameters>> to influence test
269
+ discovery and execution. However, you can provide configuration parameters within the
270
+ build script via system properties (as shown below) or via the
271
+ `junit-platform.properties` file.
272
+
273
+ [source,groovy,indent=0]
274
+ ----
275
+ test {
276
+ // ...
277
+ systemProperty("junit.jupiter.conditions.deactivate", "*")
278
+ systemProperty("junit.jupiter.extensions.autodetection.enabled", true)
279
+ systemProperty("junit.jupiter.testinstance.lifecycle.default", "per_class")
280
+ // ...
222
281
}
223
282
----
224
283
@@ -248,8 +307,8 @@ test {
248
307
249
308
Other logging frameworks provide different means to redirect messages logged using
250
309
`java.util.logging`. For example, for {Logback} you can use the
251
- https://www.slf4j.org/legacy.html#jul-to-slf4j[JUL to SLF4J Bridge] by adding an
252
- additional dependency to the runtime classpath.
310
+ https://www.slf4j.org/legacy.html#jul-to-slf4j[JUL to SLF4J Bridge] by adding it as a
311
+ dependency to the test runtime classpath.
253
312
254
313
[[running-tests-build-maven]]
255
314
==== Maven
@@ -288,7 +347,8 @@ Maven build as follows.
288
347
===== Aligning dependency versions
289
348
290
349
Unless you're using Spring Boot which defines its own way of managing dependencies, it is
291
- recommended to use the JUnit Platform BOM to align the versions of all JUnit 5 artifacts.
350
+ recommended to use the JUnit Platform <<dependency-metadata-junit-bom>> to align the
351
+ versions of all JUnit 5 artifacts.
292
352
293
353
[source,xml,indent=0]
294
354
[subs=attributes+]
@@ -580,8 +640,8 @@ managing the version of JUnit used in your project. In addition, the
580
640
Jupiter, AssertJ, Mockito, etc.
581
641
582
642
If your build relies on dependency management support from Spring Boot, you should not
583
- import the <<dependency-metadata-junit-bom,`junit-bom` >> in your build script since that
584
- will result in duplicate (and potentially conflicting) management of JUnit dependencies.
643
+ import JUnit's <<dependency-metadata-junit-bom>> in your build script since that would
644
+ result in duplicate (and potentially conflicting) management of JUnit dependencies.
585
645
586
646
If you need to override the version of a dependency used in your Spring Boot application,
587
647
you have to override the exact name of the
0 commit comments