运行TestRunner类(JUnit 5)时出现此错误,这是简单的代码。
Example1.java类包含简单的2方法验证字符串是否相等
Example1.java
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
public class Example1 {
@Test
public void test1() {
String res = "JUnit 5";
Assertions.assertEquals(res, "JUnit 5", "This test case Passes");
}
@Test
public void test2() {
String res = "JUnit 5";
Assertions.assertEquals(res, "Hello World..!!!", "This test case Failed");
}
}
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(examples.Example1.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}
输出 initializationError(examples.Example1):没有可运行的方法 假