TestJunit class
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());
}
}
I used javac -cp /root/Documents/unit\ tests/junit-4.10.jar TestJunit.java TestRunner.java
to compile and java -cp /root/Documents/unit\ tests/junit-4.10.jar:. org.junit.runner.JUnitCore TestRunner
to run. It compiles without errors. But the tests fail with an exception. My test methods are annotated with @Test. Why do I get this error?
Aucun commentaire:
Enregistrer un commentaire