TestJunitクラスJUnitテストなし実行可能な方法で例外
import org.junit.Test;
import static org.junit.Assert.assertEquals;
public class TestJunit
{
@Test
public void testAdd()
{
String str= "Junit is working fine";
assertEquals("Junit is working fine",str);
}
}
TestRunner class
/********************************************/
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(TestJunit.class);
for (Failure failure : result.getFailures()) {
System.out.println(failure.toString());
}
System.out.println(result.wasSuccessful());
}
}
私はコンパイルする
javac -cp /root/Documents/unit\ tests/junit-4.10.jar TestJunit.java TestRunner.java
を使用して
java -cp /root/Documents/unit\ tests/junit-4.10.jar:. org.junit.runner.JUnitCore TestRunner
を実行します。 エラーなしでコンパイルされますが、テストは失敗して例外が発生します。私のテスト方法には@Test
と注釈がついています。このエラーが発生するのはなぜですか?
実行時には、TestRunnerではなくTestJunitについて言及する必要があります。 – user11