1package org.junit.internal.runners; 2 3import java.lang.reflect.InvocationTargetException; 4import java.lang.reflect.Method; 5import java.lang.reflect.Modifier; 6 7import junit.framework.Test; 8 9/** 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 */ 22public class SuiteMethod extends JUnit38ClassRunner { 23 public SuiteMethod(Class<?> klass) throws Throwable { 24 super(testFromSuiteMethod(klass)); 25 } 26 27 public static Test testFromSuiteMethod(Class<?> klass) throws Throwable { 28 Method suiteMethod = null; 29 Test suite = null; 30 try { 31 suiteMethod = klass.getMethod("suite"); 32 if (!Modifier.isStatic(suiteMethod.getModifiers())) { 33 throw new Exception(klass.getName() + ".suite() must be static"); 34 } 35 suite = (Test) suiteMethod.invoke(null); // static method 36 } catch (InvocationTargetException e) { 37 throw e.getCause(); 38 } 39 return suite; 40 } 41} 42