Test Runners
Test runner is used for executing the test cases. Here is an example that assumes
the test class TestJunit already exists.
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());
}
}
JUnit Classes
JUnit classes are important classes, used in writing and testing JUnits. Some of the
important classes are −
Assert − Contains a set of assert methods.
TestCase − Contains a test case that defines the fixture to run multiple tests.
TestResult − Contains methods to collect the results of executing a test
case.