I run JUnit5 tests but receive an initializationError
(No runnable methods
). However, I have the @Test
annotation on at least one method (failingTest
). Why is failingTest
not identified as a runnable method (and the corresponding test case executed)?
File StandardTests.java
...
// See https://junit.org/junit5/docs/current/user-guide/#writing-tests-classes-and-methods
import static org.junit.jupiter.api.Assertions.fail ;
import org.junit.jupiter.api.Test ;
public class StandardTests
{
@Test
public void failingTest()
{ fail ( "a failing test" ) ; }
} // end StandardTests
And in file TestRunner.java
...
import org.junit.runner.JUnitCore ;
import org.junit.runner.Result ;
import org.junit.runner.notification.Failure ;
public class TestRunner
{
public static void main ( String [] args )
{
Result result = JUnitCore.runClasses ( StandardTests.class ) ;
for ( Failure failure : result.getFailures() )
System.out.println ( "failure: " + failure.toString() ) ;
System.out.println ( "successful: " + result.wasSuccessful() ) ;
} // end main
} // end TestRunner
I expect that method failingTest
of class StandardTests
would be identified as a JUnit5 test case and executed (that is, that failingTest
would be identified as a runnable method
and executed as a JUnit5 test case). However, the output when I run the TestRunner
is:
C:\JUnit\Minimal>C:\Progra~1\Java\JDK-12~1.1\bin\java -cp ".;junit-platform-console-standalone-1.4.2.jar" TestRunner
failure: initializationError(StandardTests): No runnable methods
successful: false
How can I get this JUnit5 test case (failingTest
) to be identified as a test case and executed?