Android TestSuite:包括除明确定义的所有TestCase之外的所有TestCase

问题:我需要调整Android Developer TestSuite示例中的代码,以便它运行包中的所有TestCase,除了一些明确定义的TestCase。 目前它只运行它们:

public class AllTests extends TestSuite { public static Test suite() { return new TestSuiteBuilder(AllTests.class) .includeAllPackagesUnderHere() .build(); } } 

看一下TestSuiteBuilder的Docs ,也许我可以通过添加对TestSuiteBuilder的addRequirements()方法的调用来调整上面的代码,但是如果这样做的话,我不能做出正面或反面,或者应该用它来做。

如果addRequirements将用于排除AndroidTestCases,我该如何调用它? 我不明白我会通过什么论点,文件说:

 addRequirements(Predicate... predicates) //Exclude tests that fail to satisfy all of the given predicates. 

但我找不到关于类Predicate的存在或者应该如何填充以实现我的目标的任何内容。

谢谢

我想在开发期间运行unit testing时排除InstrumentationTestCases,以便能够在没有function测试的情况下立即运行测试套件。

我是这样做的:

 public class FastTestSuite extends TestSuite { public static Test suite() { // get the list of all the tests using the default testSuiteBuilder TestSuiteBuilder b = new TestSuiteBuilder(FastTestSuite.class); b.includePackages("com.your.package.name"); TestSuite allTest = b.build(); // select the tests that are NOT subclassing InstrumentationTestCase TestSuite selectedTests = new TestSuite(); for (Test test : Collections.list(allTest.tests())) { if (test instanceof TestSuite) { TestSuite suite = (TestSuite) test; String classname = suite.getName(); try { Class clazz = Class.forName(classname); if (!InstrumentationTestCase.class.isAssignableFrom(clazz)) { selectedTests.addTest(test); } } catch (Exception e) { continue; } } } return selectedTests; } } 

我决定只提供我想要的所有内容。

http://developer.android.com/reference/junit/framework/TestSuite.html

TestSuite似乎没有removeTestSuite方法或类似方法,因此我不能取消包含TestSuiteBuilder将为其构建的测试添加的任何测试。 如果有人能解释如何使用addRequirements(…)方法排除/包含测试,我将不胜感激。