I'm trying to use JUnit 5 in my side project as a trial before migrating my main project. I'd like to use @Nested tests to make my test classes cleaner.
Everything is fine when I ran my test suite as a whole. However, as soon as I try running just a single test, @Nested ones are not executed.
mvn -Dtest=com.mycompany.test.MyTest surefire:test
Is there any way of getting it to run the selected class and all @Nested ones?
Using JUnit 5.1.0, JUnit platform 1.1.0
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${org.junit.platform.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${org.junit.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
Test class:
public class MyTest {
@Test
public void thisTestExecutes() { }
@Nested
public class NestedTests {
@Test
public void thisTestDoesnt() { }
}
}