|
28 | 28 | import junit.framework.TestSuite; |
29 | 29 | import junit.runner.BaseTestRunner; |
30 | 30 |
|
| 31 | +import java.lang.reflect.Constructor; |
31 | 32 | import java.lang.reflect.InvocationTargetException; |
32 | 33 | import java.util.List; |
33 | 34 |
|
@@ -91,15 +92,35 @@ private Class<? extends Test> loadTestClass(String testClassName) { |
91 | 92 |
|
92 | 93 | private TestCase buildSingleTestMethod(Class testClass, String testMethodName) { |
93 | 94 | try { |
94 | | - TestCase testCase = (TestCase) testClass.newInstance(); |
| 95 | + Constructor c = testClass.getConstructor(); |
| 96 | + return newSingleTestMethod(testClass, testMethodName, c); |
| 97 | + } catch (NoSuchMethodException e) { |
| 98 | + } |
| 99 | + |
| 100 | + try { |
| 101 | + Constructor c = testClass.getConstructor(String.class); |
| 102 | + return newSingleTestMethod(testClass, testMethodName, c, testMethodName); |
| 103 | + } catch (NoSuchMethodException e) { |
| 104 | + } |
| 105 | + |
| 106 | + return null; |
| 107 | + } |
| 108 | + |
| 109 | + private TestCase newSingleTestMethod(Class testClass, String testMethodName, |
| 110 | + Constructor constructor, Object... args) { |
| 111 | + try { |
| 112 | + TestCase testCase = (TestCase) constructor.newInstance(args); |
95 | 113 | testCase.setName(testMethodName); |
96 | 114 | return testCase; |
97 | 115 | } catch (IllegalAccessException e) { |
98 | 116 | runFailed("Could not access test class. Class: " + testClass.getName()); |
99 | 117 | } catch (InstantiationException e) { |
100 | 118 | runFailed("Could not instantiate test class. Class: " + testClass.getName()); |
| 119 | + } catch (IllegalArgumentException e) { |
| 120 | + runFailed("Illegal argument passed to constructor. Class: " + testClass.getName()); |
| 121 | + } catch (InvocationTargetException e) { |
| 122 | + runFailed("Constructor thew an exception. Class: " + testClass.getName()); |
101 | 123 | } |
102 | | - |
103 | 124 | return null; |
104 | 125 | } |
105 | 126 |
|
|
0 commit comments