Studio中的多个测试套件

Studio中的多个测试套件

本文介绍了Android Studio中的多个测试套件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Android项目中有一个纯Java子项目。我已经有了一个位于 src / test / java 内的测试套件,我希望为集成测试引入第二套测试套件。



我在 build.gradle 中指定了如下内容:

  sourceSets {
integration {
java {
compileClasspath + = test.compileClasspath
runtimeClasspath + = test.runtimeClasspath
}
}


任务integrationTest(类型:Test,description:'运行集成测试',group:'Verification'){
testClassesDir = sourceSets.integration.output.classesDir
classpath = sourceSets.integration.runtimeClasspath
}

configuration {
integrationCompile.extendsFrom testCompile
integrationRuntime.extendsFrom testRuntime
}

测试位于 src / integration / java 内。这些测试可以从命令行成功运行,并且在Android Studio中, java 文件夹以绿色显示,如主测试套件。



但是当右键单击并选择运行所有测试时,我得到错误没有找到测试,空测试套件。。



如何获得可以从Android Studio轻松运行的第二个测试套件?

解决方案

您可以使用 SuiteClasses 来尝试。例如,如果您在一个包中有多个Test类,那么您可以创建一个运行所需套件的 Suite.class ,只要您指定它们即可进行所有测试。然后右键单击并在该类上运行测试。这里是例子:

$ pre $ @ $ $ $ $ $ $ $ $ $ EmailValidatorTest.class ,
NewTest.class})

public class AllTests {

}

结构示例:


I have a pure Java sub-project within my Android project. I already have a test suite located within src/test/java, and I wish to introduce a second test suite for integration tests.

I have specified this within my build.gradle as follows:

sourceSets {
    integration {
        java {
            compileClasspath += test.compileClasspath
            runtimeClasspath += test.runtimeClasspath
        }
    }
}

task integrationTest(type: Test, description: 'Runs the integration tests.', group: 'Verification') {
    testClassesDir = sourceSets.integration.output.classesDir
    classpath = sourceSets.integration.runtimeClasspath
}

configurations {
    integrationCompile.extendsFrom testCompile
    integrationRuntime.extendsFrom testRuntime
}

with tests located within src/integration/java. These tests can be run successfully from the command line, and within Android Studio, the java folder appears in green like the main test suite.

But when right-clicking and choosing "Run 'All Tests'", I get the errors No tests were found, Empty test suite..

How can I have a second test suite that can be run easily from within Android Studio?

解决方案

You can try by using SuiteClasses. For example if you have multiple Test classes in a package you can create a Suite.class that is running the suites you want, even all tests as long as you specify them. Then right click and run test on that class. Here is example:

@RunWith(Suite.class)
@SuiteClasses({
        EmailValidatorTest.class,
        NewTest.class })

public class AllTests {

}

Example structure:

这篇关于Android Studio中的多个测试套件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-16 01:06