01: package org.junit.runners;
02:
03: import java.lang.reflect.InvocationTargetException;
04: import java.lang.reflect.Method;
05: import java.lang.reflect.Modifier;
06:
07: import junit.framework.Test;
08: import org.junit.internal.runners.JUnit38ClassRunner;
09:
10: /** Runner for use with JUnit 3.8.x-style AllTests classes
11: * (those that only implement a static <code>suite()</code>
12: * method). For example:
13: * <pre>
14: * @RunWith(AllTests.class)
15: * public class ProductTests {
16: * public static junit.framework.Test suite() {
17: * ...
18: * }
19: * }
20: * </pre>
21: */
22: public class AllTests extends JUnit38ClassRunner {
23: @SuppressWarnings("unchecked")
24: public AllTests(Class<?> klass) throws Throwable {
25: super (testFromSuiteMethod(klass));
26: }
27:
28: public static Test testFromSuiteMethod(Class<?> klass)
29: throws Throwable {
30: Method suiteMethod = null;
31: Test suite = null;
32: try {
33: suiteMethod = klass.getMethod("suite");
34: if (!Modifier.isStatic(suiteMethod.getModifiers())) {
35: throw new Exception(klass.getName()
36: + ".suite() must be static");
37: }
38: suite = (Test) suiteMethod.invoke(null); // static method
39: } catch (InvocationTargetException e) {
40: throw e.getCause();
41: }
42: return suite;
43: }
44: }
|