I run mvn clean package
and all other tests run except the suite test. I'm running both Junit 4 and 5 tests - @Rules tests run and @RegisterExtension/@ExtendWith tests also run. Not sure why the suite will not run - any ideas?
The code follows:
Test suite
@SelectPackages("com.company.platform.test.suite")
@IncludeClassNamePatterns({"^.*Suite$"})
public class SuiteTest {
}
Test being called by SuiteTest
import org.assertj.core.api.Assertions;
import org.junit.jupiter.api.Test;
public class TestingSuite {
@Test
public void add_2_plus_1(){
Assertions.assertThat(2 + 1).isEqualTo(3);
}
}
Pom
<junit-jupiter-engine.version>5.5.0</junit-jupiter-engine.version>
<junit-platform-runner.version>1.5.0</junit-platform-runner.version>
<!-- ellided -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit-jupiter-engine.version}</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>${junit-jupiter-engine.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit-platform-runner.version}</version>
</dependency>
<!-- ellided -->
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
<configuration>
<includes>
<include>**/*Test.java</include>
</includes>
</configuration>
</plugin>
Maven, Java and OS details
mvn11 --version Sun Jul 21 14:43:24 EDT 2019
Apache Maven 3.5.4 (1edded0938998edf8bf061f1ceb3cfdeccf443fe; 2018-06-17T14:33:14-04:00)
Maven home: /usr/local/Cellar/maven/3.5.4/libexec
Java version: 11.0.1, vendor: Oracle Corporation, runtime: /Users/me/Downloads/jdk-11.0.1.jdk/Contents/Home
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "10.14.5", arch: "x86_64", family: "mac"
So I replicated your problem. When running
mvn clean test
i got the following output (among many others):
Juli 23, 2019 8:17:30 VORM. org.junit.vintage.engine.discovery.DefensiveAllDefaultPossibilitiesBuilder$DefensiveAnnotatedBuilder buildRunner
WARNING: Ignoring test class using JUnitPlatform runner: com.example.project.SuiteTest
That's why I looked up the code of DefensiveAllDefaultPossibilitiesBuilder$DefensiveAnnotatedBuilder
and found the following comment:
/**
* Customization of {@link AnnotatedBuilder} that ignores classes annotated
* with {@code @RunWith(JUnitPlatform.class)} to avoid infinite recursion.
*/
private static class DefensiveAnnotatedBuilder extends AnnotatedBuilder {...}
This strongly suggests that suites using @RunWith(JUnitPlatform.class)
are ignored when run through the platform mechanism. You might ask the junit 5 team if there is an explicit way to switch that security mechanism off but I'd guess there is none.
I suggest you extend the configuration of maven-surefire-plugin to mimic what you do in the suite:
@SelectPackages("com.company.platform.test.suite")
@IncludeClassNamePatterns({"^.*Suite$"})
can be translated into something like
<include>com.company.platform.test.suite/*Suite.java</include>
I didn't test it though.