Skip to content
Permalink
Browse files

defend against NoClassDefFoundError when junit is not available on cp

  • Loading branch information...
lukasj committed Feb 5, 2012
1 parent 543fc9c commit 77de21b33f251751947a7d33dd691b09c427d900
Showing with 6 additions and 3 deletions.
  1. +6 −3 src/main/java/org/testng/junit/JUnitTestFinder.java
@@ -9,14 +9,16 @@
*/
public final class JUnitTestFinder {

private static final String JUNIT3_TEST = "junit.framework.Test";
private static final String JUNIT3_FINDER = "org.testng.junit.JUnit3TestRecognizer";
private static final String JUNIT4_TEST = "org.junit.Test";
private static final String JUNIT4_FINDER = "org.testng.junit.JUnit4TestRecognizer";
private static final JUnitTestRecognizer junit3;
private static final JUnitTestRecognizer junit4;

static {
junit3 = getJUnitTestRecognizer(JUNIT3_FINDER);
junit4 = getJUnitTestRecognizer(JUNIT4_FINDER);
junit3 = getJUnitTestRecognizer(JUNIT3_TEST, JUNIT3_FINDER);
junit4 = getJUnitTestRecognizer(JUNIT4_TEST, JUNIT4_FINDER);
if (junit3 == null) {
Utils.log("JUnitTestFinder", 2, "JUnit3 was not found on the classpath");

@@ -41,8 +43,9 @@ private static boolean haveJUnit() {
return junit3 != null || junit4 != null;
}

private static JUnitTestRecognizer getJUnitTestRecognizer(String name) {
private static JUnitTestRecognizer getJUnitTestRecognizer(String test, String name) {
try {
Class.forName(test);
Class<JUnitTestRecognizer> c = (Class<JUnitTestRecognizer>) Class.forName(name);
return c.newInstance();
} catch (Throwable t) {

0 comments on commit 77de21b

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