我运行 JUnit5 测试但收到initializationError( No runnable methods)。但是,我@Test至少有一个方法 ( failingTest) 的注释。为什么failingTest不被识别为可运行方法(并执行相应的测试用例)?
文件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
并在文件中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
failingTest我希望类的方法StandardTests将被识别为 JUnit5 测试用例并执行(也就是说,failingTest将被识别为runnable method并作为 JUnit5 测试用例执行)。但是,我运行时的输出TestRunner是:
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
我如何才能将这个 JUnit5 测试用例 ( failingTest) 识别为测试用例并执行?
慕妹3146593
相关分类