在JUnit4中可以吗?
在JUnit3中,我将执行以下操作:
public class MyTestSuite { public static Test suite() throws Exception { doBeforeActions(); try { TestSuite testSuite = new TestSuite(); for(Class clazz : getAllClassesInPackage("com.mypackage")){ testSuite.addTestSuite(clazz); } return testSuite; } finally { doAfterActions } } ... }
takari-cpsuite(最初由Johannes Link开发)提供了一个适合您需求的classpath- suite。它允许通过正则表达式对Classpath中的类进行过滤,例如:
import org.junit.extensions.cpsuite.ClasspathSuite.*; ... @ClassnameFilters({"mytests.*", ".*Test"}) public class MySuite...