1

我的测试所在的位置有几个包:

  1. com.example.tests.common - 适用于手机和平板电脑
  2. com.example.tests.phones - 仅限手机
  3. com.example.tests.tablets - 仅限平板电脑

现在要为手机运行测试,我需要运行位于类commonphones包中的测试——两​​次运行。平板电脑也是如此。

我需要他们一次性运行平板电脑/手机的所有测试。TestSuite的示例对我不起作用:

 Class[] testClasses = { MathTest.class, AnotherTest.class }
 TestSuite suite= new TestSuite(testClasses);

它不适用于错误,没有这样的构造函数TestSuite

所以问题是:1.为什么它不能按照示例工作。

  1. 还有其他方法可以将所需的类/包放在一起suite吗?

非常感谢。

4

3 回答 3

2

Normally it is better to name test suite packages like test.com.example.phones, adding test. prefix to the package name. This allows to run, relocate or move all tests very easily in one go. If it is important to care about device-specific tests, another approach would be like test.phones.com.example and test.tablets.com.example.

While it is also possible to have test suites, these are often redundant. The most frequent test types are running all tests for the package being tested and running all tests available. If the test packages mirror the main packages, such runs can be easily launched from IDE that provides features to run all tests in a folder/package (right click and select "run as Android test" in Eclipse). And during automated builds in the cloud usually all tests must run anyway.

If you have more tests, not a bad idea is to create a separate testing project.

于 2013-02-13T18:05:47.267 回答
1
  1. TestSuite(Class[])没有构造函数
  2. 您可以使用变量参数列表:

    TestSuite suite = new TestSuite(MathTest.class, AnotherTest.class);
    
  3. 或者像你之前做的那样的数组,但你必须用一个字符串来识别它:

    TestSuite suite = new TestSuite({MathTest.class, AnotherTest.class}, "Example");
    
于 2013-02-13T18:06:57.143 回答
0

我真正想要的是一个TestSuiteBuilder

这是我现在拥有的:

public class TabletAllTests extends TestSuite {

    public static Test suite() {

        TestSuiteBuilder suiteBuilder = new TestSuiteBuilder(PhoneAllTests.class);
        suiteBuilder.includePackages("<my_package>.test.common");
        suiteBuilder.includePackages("<my_package>.test.tablet");

        return suiteBuilder.build();
    }
}

同样的PhoneAllTests

于 2013-02-13T18:36:02.810 回答