Skip to content

Commit e237189

Browse files
committed
Document how to execute static nested test classes using Maven Surefire
Resolves #1378.
1 parent b9ab2bf commit e237189

File tree

4 files changed

+45
-12
lines changed

4 files changed

+45
-12
lines changed

documentation/documentation.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ asciidoctor {
115115
'mainDir': project.sourceSets.main.java.srcDirs[0],
116116
'testDir': project.sourceSets.test.java.srcDirs[0],
117117
'kotlinTestDir': project.sourceSets.test.kotlin.srcDirs[0],
118+
'surefire-version': surefireVersion,
118119
'consoleLauncherOptionsFile': consoleLauncherOptionsFile.toString(),
119120
'experimentalApisTableFile': experimentalApisTableFile.toString(),
120121
'testResourcesDir': project.sourceSets.test.resources.srcDirs[0],

documentation/src/docs/asciidoc/user-guide/running-tests.adoc

Lines changed: 41 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -208,12 +208,13 @@ additional dependency to the runtime classpath.
208208
[[running-tests-build-maven]]
209209
==== Maven
210210

211-
The JUnit team has developed a very basic provider for Maven Surefire that lets you run
212-
JUnit 4 and JUnit Jupiter tests via `mvn test`. The `pom.xml` file in the
211+
The JUnit team has developed a basic provider for Maven Surefire that lets you run JUnit 4
212+
and JUnit Jupiter tests via `mvn test`. The `pom.xml` file in the
213213
`{junit5-maven-consumer}` project demonstrates how to use it and can serve as a starting
214214
point.
215215

216-
NOTE: Please use Maven Surefire 2.21.0 with the `junit-platform-surefire-provider`.
216+
NOTE: Please use Maven Surefire {surefire-version} with the
217+
`junit-platform-surefire-provider`.
217218

218219
[source,xml,indent=0]
219220
[subs=attributes+]
@@ -224,7 +225,7 @@ NOTE: Please use Maven Surefire 2.21.0 with the `junit-platform-surefire-provide
224225
...
225226
<plugin>
226227
<artifactId>maven-surefire-plugin</artifactId>
227-
<version>2.21.0</version>
228+
<version>{surefire-version}</version>
228229
<dependencies>
229230
<dependency>
230231
<groupId>org.junit.platform</groupId>
@@ -257,7 +258,7 @@ dependencies of the `maven-surefire-plugin` similar to the following.
257258
...
258259
<plugin>
259260
<artifactId>maven-surefire-plugin</artifactId>
260-
<version>2.21.0</version>
261+
<version>{surefire-version}</version>
261262
<dependencies>
262263
<dependency>
263264
<groupId>org.junit.platform</groupId>
@@ -299,7 +300,7 @@ the dependencies of the `maven-surefire-plugin` similar to the following.
299300
...
300301
<plugin>
301302
<artifactId>maven-surefire-plugin</artifactId>
302-
<version>2.21.0</version>
303+
<version>{surefire-version}</version>
303304
<dependencies>
304305
<dependency>
305306
<groupId>org.junit.platform</groupId>
@@ -347,11 +348,39 @@ the following patterns.
347348

348349
- `+**/Test*.java+`
349350
- `+**/*Test.java+`
350-
- `+**/*Tests.java+` _(supported since Surefire 2.20)_
351+
- `+**/*Tests.java+`
351352
- `+**/*TestCase.java+`
352353

354+
Moreover, it will exclude all nested classes (including static member classes) by default.
355+
353356
Note, however, that you can override this default behavior by configuring explicit
354-
`include` and `exclude` rules in your `pom.xml` file. See the
357+
`include` and `exclude` rules in your `pom.xml` file. For example, to keep Maven Surefire
358+
from excluding static member classes, you can override its exclude rules.
359+
360+
[source,xml,indent=0]
361+
[subs=attributes+]
362+
.Overriding exclude rules of Maven Surefire
363+
----
364+
...
365+
<build>
366+
<plugins>
367+
...
368+
<plugin>
369+
<artifactId>maven-surefire-plugin</artifactId>
370+
<version>{surefire-version}</version>
371+
<configuration>
372+
<excludes>
373+
<exclude/>
374+
</excludes>
375+
</configuration>
376+
...
377+
</plugin>
378+
</plugins>
379+
</build>
380+
...
381+
----
382+
383+
Please see the
355384
https://maven.apache.org/surefire/maven-surefire-plugin/examples/inclusion-exclusion.html[Inclusions and Exclusions of Tests]
356385
documentation for Maven Surefire for details.
357386

@@ -365,14 +394,15 @@ the following configuration properties.
365394
- to exclude _tags_ or _tag expressions_, use either `excludedGroups` or `excludeTags`.
366395

367396
[source,xml,indent=0]
397+
[subs=attributes+]
368398
----
369399
...
370400
<build>
371401
<plugins>
372402
...
373403
<plugin>
374404
<artifactId>maven-surefire-plugin</artifactId>
375-
<version>2.21.0</version>
405+
<version>{surefire-version}</version>
376406
<configuration>
377407
<properties>
378408
<includeTags>acceptance | !feature-a</includeTags>
@@ -397,14 +427,15 @@ property and providing key-value pairs using the Java `Properties` file syntax (
397427
below) or via the `junit-platform.properties` file.
398428

399429
[source,xml,indent=0]
430+
[subs=attributes+]
400431
----
401432
...
402433
<build>
403434
<plugins>
404435
...
405436
<plugin>
406437
<artifactId>maven-surefire-plugin</artifactId>
407-
<version>2.21.0</version>
438+
<version>{surefire-version}</version>
408439
<configuration>
409440
<properties>
410441
<configurationParameters>

gradle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ log4jVersion = 2.11.0
2828
mockitoVersion = 2.18.0
2929
ota4jVersion = 1.0.0
3030
shadowVersion = 2.0.3
31+
surefireVersion = 2.21.0
3132

3233
defaultBuiltBy = JUnit Team
3334
releaseBranch = master

junit-platform-surefire-provider/junit-platform-surefire-provider.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ junitPlatform {
1414

1515
dependencies {
1616
api(project(':junit-platform-launcher'))
17-
implementation('org.apache.maven.surefire:surefire-api:2.21.0')
18-
implementation('org.apache.maven.surefire:common-java5:2.21.0')
17+
implementation("org.apache.maven.surefire:surefire-api:${surefireVersion}")
18+
implementation("org.apache.maven.surefire:common-java5:${surefireVersion}")
1919

2020
testImplementation(project(':junit-jupiter-api'))
2121
testImplementation(project(':junit-platform-runner'))

0 commit comments

Comments
 (0)