Skip to content

Commit 1859027

Browse files
committed
[SUREFIRE-2040] No tests executed with junit-platform-suite and -Dtest=TestSuite
1 parent 68bca29 commit 1859027

File tree

7 files changed

+227
-3
lines changed

7 files changed

+227
-3
lines changed

maven-surefire-plugin/src/site/apt/examples/junit-platform.apt.vm

+37
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ Using JUnit 5 Platform
294294
<plugin>
295295
<groupId>org.apache.maven.plugins</groupId>
296296
<artifactId>maven-surefire-plugin</artifactId>
297+
<version>${project.version}</version>
297298
<dependencies>
298299
<dependency>
299300
<groupId>org.junit.jupiter</groupId>
@@ -334,6 +335,7 @@ Using JUnit 5 Platform
334335
<plugin>
335336
<groupId>org.apache.maven.plugins</groupId>
336337
<artifactId>maven-surefire-plugin</artifactId>
338+
<version>${project.version}</version>
337339
<dependencies>
338340
<dependency>
339341
<groupId>org.junit.vintage</groupId>
@@ -411,6 +413,41 @@ Using JUnit 5 Platform
411413
</dependencies>
412414
+---+
413415

416+
** JUnit5 Suite
417+
418+
For more information see this
419+
{{{https://github.com/apache/maven-surefire/tree/master/surefire-its/src/test/resources/junit5-suite}example}}
420+
and the {{{https://junit.org/junit5/docs/current/user-guide/#junit-platform-suite-engine}tutorial}}.
421+
422+
+---+
423+
<dependencies>
424+
<dependency>
425+
<groupId>org.junit.jupiter</groupId>
426+
<artifactId>junit-jupiter-engine</artifactId>
427+
<version>5.8.2</version>
428+
<scope>test</scope>
429+
</dependency>
430+
<dependency>
431+
<groupId>org.junit.platform</groupId>
432+
<artifactId>junit-platform-suite-engine</artifactId>
433+
<version>1.8.2</version>
434+
<scope>test</scope>
435+
</dependency>
436+
</dependencies>
437+
<build>
438+
<plugins>
439+
<plugin>
440+
<groupId>org.apache.maven.plugins</groupId>
441+
<artifactId>maven-surefire-plugin</artifactId>
442+
<version>${project.version}</version>
443+
<configuration>
444+
<test>JUnit5Tests</test>
445+
</configuration>
446+
</plugin>
447+
</plugins>
448+
</build>
449+
+---+
450+
414451
* Provider Selection
415452

416453
If nothing is configured, Surefire detects which JUnit version to use by the following algorithm:

surefire-its/src/test/java/org/apache/maven/surefire/its/jiras/Surefire1787JUnit5IT.java

+16
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
import org.apache.maven.surefire.its.fixture.SurefireJUnit4IntegrationTestCase;
2323
import org.junit.Test;
2424

25+
import static org.hamcrest.Matchers.containsString;
26+
import static org.hamcrest.Matchers.equalTo;
27+
2528
/**
2629
*
2730
*/
@@ -129,4 +132,17 @@ public void junit4Runner()
129132
.verifyTextInLog( "Running pkg.JUnit5Tests" )
130133
.verifyTextInLog( "Using auto detected provider org.apache.maven.surefire.junit4.JUnit4Provider" );
131134
}
135+
136+
@Test
137+
public void junit5Suite() throws Exception
138+
{
139+
unpack( "junit5-suite" )
140+
.executeTest()
141+
.verifyErrorFree( 1 )
142+
.verifyTextInLog(
143+
"Using auto detected provider org.apache.maven.surefire.junitplatform.JUnitPlatformProvider" )
144+
.verifyTextInLog( "Running pkg.JUnit5Test" )
145+
.verifyTextInLog( "Running pkg.domain.AxTest" )
146+
.assertThatLogLine( containsString( "Running pkg.domain.BxTest" ), equalTo( 0 ) );
147+
}
132148
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Licensed to the Apache Software Foundation (ASF) under one
4+
~ or more contributor license agreements. See the NOTICE file
5+
~ distributed with this work for additional information
6+
~ regarding copyright ownership. The ASF licenses this file
7+
~ to you under the Apache License, Version 2.0 (the
8+
~ "License"); you may not use this file except in compliance
9+
~ with the License. You may obtain a copy of the License at
10+
~
11+
~ http://www.apache.org/licenses/LICENSE-2.0
12+
~
13+
~ Unless required by applicable law or agreed to in writing,
14+
~ software distributed under the License is distributed on an
15+
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16+
~ KIND, either express or implied. See the License for the
17+
~ specific language governing permissions and limitations
18+
~ under the License.
19+
-->
20+
21+
<project xmlns="http://maven.apache.org/POM/4.0.0"
22+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
23+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
24+
<modelVersion>4.0.0</modelVersion>
25+
26+
<groupId>org.example</groupId>
27+
<artifactId>junit5-suite</artifactId>
28+
<version>1.0-SNAPSHOT</version>
29+
30+
<properties>
31+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
32+
<maven.compiler.source>${java.specification.version}</maven.compiler.source>
33+
<maven.compiler.target>${java.specification.version}</maven.compiler.target>
34+
</properties>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>org.junit.jupiter</groupId>
39+
<artifactId>junit-jupiter-api</artifactId>
40+
<version>5.8.0</version>
41+
<scope>test</scope>
42+
</dependency>
43+
<dependency>
44+
<groupId>org.junit.platform</groupId>
45+
<artifactId>junit-platform-suite-api</artifactId>
46+
<version>1.8.0</version>
47+
<scope>test</scope>
48+
</dependency>
49+
</dependencies>
50+
51+
<build>
52+
<pluginManagement>
53+
<plugins>
54+
<plugin>
55+
<groupId>org.apache.maven.plugins</groupId>
56+
<artifactId>maven-surefire-plugin</artifactId>
57+
<version>${surefire.version}</version>
58+
<configuration>
59+
<test>JUnit5Tests</test>
60+
</configuration>
61+
<dependencies>
62+
<dependency>
63+
<groupId>org.junit.jupiter</groupId>
64+
<artifactId>junit-jupiter-engine</artifactId>
65+
<version>5.8.2</version>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.junit.platform</groupId>
69+
<artifactId>junit-platform-suite-engine</artifactId>
70+
<version>1.8.2</version>
71+
</dependency>
72+
</dependencies>
73+
</plugin>
74+
</plugins>
75+
</pluginManagement>
76+
</build>
77+
78+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package pkg;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import org.junit.platform.suite.api.SelectClasses;
23+
import org.junit.platform.suite.api.Suite;
24+
25+
@Suite
26+
@SelectClasses({pkg.domain.AxTest.class})
27+
public class JUnit5Tests
28+
{
29+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package pkg.domain;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
public class AxTest
25+
{
26+
@Test
27+
void test()
28+
{
29+
}
30+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package pkg.domain;
2+
3+
/*
4+
* Licensed to the Apache Software Foundation (ASF) under one
5+
* or more contributor license agreements. See the NOTICE file
6+
* distributed with this work for additional information
7+
* regarding copyright ownership. The ASF licenses this file
8+
* to you under the Apache License, Version 2.0 (the
9+
* "License"); you may not use this file except in compliance
10+
* with the License. You may obtain a copy of the License at
11+
*
12+
* http://www.apache.org/licenses/LICENSE-2.0
13+
*
14+
* Unless required by applicable law or agreed to in writing,
15+
* software distributed under the License is distributed on an
16+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17+
* KIND, either express or implied. See the License for the
18+
* specific language governing permissions and limitations
19+
* under the License.
20+
*/
21+
22+
import org.junit.jupiter.api.Test;
23+
24+
import static org.junit.jupiter.api.Assertions.fail;
25+
26+
public class BxTest
27+
{
28+
@Test
29+
void test()
30+
{
31+
fail();
32+
}
33+
}

surefire-providers/surefire-junit-platform/src/main/java/org/apache/maven/surefire/junitplatform/JUnitPlatformProvider.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import static org.apache.maven.surefire.api.report.ConsoleOutputCapture.startCapture;
3333
import static org.apache.maven.surefire.api.report.RunMode.NORMAL_RUN;
3434
import static org.apache.maven.surefire.api.report.RunMode.RERUN_TEST_AFTER_FAILURE;
35+
import static org.apache.maven.surefire.api.testset.TestListResolver.optionallyWildcardFilter;
3536
import static org.apache.maven.surefire.api.util.TestsToRun.fromClass;
3637
import static org.apache.maven.surefire.shared.utils.StringUtils.isBlank;
3738
import static org.junit.platform.engine.discovery.DiscoverySelectors.selectClass;
@@ -275,10 +276,10 @@ private Filter<?>[] newFilters()
275276
.map( TagFilter::excludeTags )
276277
.ifPresent( filters::add );
277278

278-
TestListResolver testListResolver = parameters.getTestRequest().getTestListResolver();
279-
if ( !testListResolver.isEmpty() )
279+
TestListResolver filter = optionallyWildcardFilter( parameters.getTestRequest().getTestListResolver() );
280+
if ( !filter.isEmpty() && !filter.isWildcard() )
280281
{
281-
filters.add( new TestMethodFilter( testListResolver ) );
282+
filters.add( new TestMethodFilter( filter ) );
282283
}
283284

284285
getPropertiesList( INCLUDE_JUNIT5_ENGINES_PROP )

0 commit comments

Comments
 (0)