[英]JUnit4 run all tests in a specific package using a testsuite
在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...
您可以使用JUnitToolBox:
@RunWith(WildcardPatternSuite.class)
@SuiteClasses("**/*Test.class")
public class MySuite {
}
Maven配置:
<dependency>
<groupId>com.googlecode.junit-toolbox</groupId>
<artifactId>junit-toolbox</artifactId>
<version>1.5</version>
</dependency>
有關更多詳細信息,請參見https://code.google.com/p/junit-toolbox/ 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.