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