Skip to content
Permalink
Browse files

Defend against JUnit missing on the classpath

  • Loading branch information...
lukasj committed Feb 6, 2012
1 parent 2e805d9 commit 44c68b0cae4af8963c4485643d06cd8505448112
Showing with 4 additions and 0 deletions.
  1. +4 −0 src/main/java/org/testng/internal/ClassHelper.java
@@ -198,17 +198,21 @@ public static ConstructorOrMethod findDeclaredFactoryMethod(Class<?> cls,
public static IJUnitTestRunner createTestRunner(TestRunner runner) {
try {
//try to get runner for JUnit 4 first
Class.forName("org.junit.Test");
IJUnitTestRunner tr = (IJUnitTestRunner) ClassHelper.forName(JUNIT_4_TESTRUNNER).newInstance();
tr.setTestResultNotifier(runner);
return tr;
} catch (Throwable t) {
Utils.log("ClassHelper", 2, "JUnit 4 was not found on the classpath");
try {
//fallback to JUnit 3
Class.forName("junit.framework.Test");
IJUnitTestRunner tr = (IJUnitTestRunner) ClassHelper.forName(JUNIT_TESTRUNNER).newInstance();
tr.setTestResultNotifier(runner);

return tr;
} catch (Exception ex) {
Utils.log("ClassHelper", 2, "JUnit 3 was not found on the classpath");
//there's no JUnit on the classpath
throw new TestNGException("Cannot create JUnit runner", ex);
}

0 comments on commit 44c68b0

Please sign in to comment.
You can’t perform that action at this time.