JUnit4 使用测试套件运行特定包中的所有测试 [英] JUnit4 run all tests in a specific package using a testsuite

查看:32
本文介绍了JUnit4 使用测试套件运行特定包中的所有测试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这在 JUnit4 中可行吗?

Is this possible in JUnit4?

在 JUnit3 中,我将执行以下操作:

In JUnit3, I would do the following:

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 中的类,例如:

The takari-cpsuite (originally developed by Johannes Link) offers a classpath-suite which should fit your needs. It allows filtering of classes in the Classpath by regular expressions like:

import org.junit.extensions.cpsuite.ClasspathSuite.*;
...
@ClassnameFilters({"mytests.*", ".*Test"})
public class MySuite...

这篇关于JUnit4 使用测试套件运行特定包中的所有测试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆