我怎样才能运行一组特定的与Android的摇篮仪器测试? [英] How can I run a specific set of Android instrumentation tests with Gradle?

查看:123
本文介绍了我怎样才能运行一组特定的与Android的摇篮仪器测试?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有多个测试包:

com.mypackage.blackbox    - Robotium UI tests
com.mypackage.integration - REST integration tests
com.mypackage.unit        - low level unit tests

我们的服务器团队需要能够在每次推送只运行集成测试(他们需要几分钟的时间),但随后运行所有测试,每天晚上(黑匣子UI测试需要超过10分钟)。

Our server team needs to be able to run just the integration tests on every push (they take a couple of minutes), but then run all tests every night (the black box UI tests take more than 10 minutes).

这个伟大的答案提供了一个稍微哈克(但有效)的方式通过重载现有的JUnit的注释,比如<做code> @SmallTest 或 @LargeTest

This great answer provides a slightly hacky (but effective) way to do it by overloading an existing JUnit annotation like @SmallTest or @LargeTest.

的摇篮文档表明,测试过滤器的方式要做到这一点,例如

The Gradle documentation suggests that test filters are the way to do this, e.g.

./gradlew connectedAndroidTestDevDebug --tests com.mypackage.integration.*

不过,失败与&GT;未知的命令行选项--tests。错误(presumably因为Android的摇篮插件不支持一切香草摇篮呢?)。

However, that fails with an > Unknown command-line option '--tests'. error (presumably because the Android Gradle plugin doesn't support everything that vanilla Gradle does?).

同样的文件说,在未来,他们计划以支持这些替代品:

The same documentation says in future they plan to support these alternatives:

      
  • 在基于自定义注释过滤(未来)
  •   
  • 根据测试层次过滤;执行所有扩展ceratain基类(未来)测试
  •   
  • 基于一些自定义运行规则,比如过滤系统属性或某些静止状态(未来)的特定值
  •   
  • Filtering based on custom annotations (future)
  • Filtering based on test hierarchy; executing all tests that extend ceratain base class (future)
  • Filtering based on some custom runtime rule, e.g. particular value of a system property or some static state (future)

是否有人知道一个干净的方式来得到这个工作的权利吗?现在我打算使用的基类,我所有的集成测试延长 @MediumTest 标注,但我很想能够指定特定的包(S ) 代替。使用 @MediumTest @LargeTest 滥用这些批注,既是我的整合和黑箱测试是大规模测试的根据准则

Does anybody know a clean way to get this to work right now? For now I'm planning to use the @MediumTest annotation on the base class that all my integration tests extend, but I'd love to be able to specify particular package(s) instead. Using @MediumTest or @LargeTest abuses those annotations, as both my integration and black box tests are large tests according to the guidelines.

推荐答案

要运行使用摇篮,你必须创建自定义的仪器测试运行器类和使用该类运行测试具体的测试。即创建类

To run specific tests using gradle you have to create custom instrumentation test runner class and run tests using that class. I.e. create class

package com.my.package;

public class MyInstrumentationTestRunner extends InstrumentationTestRunner {
    @Override
    public void onCreate(Bundle instrumentationArguments) {
        instrumentationArguments.putString("size", "medium"); // Run medium tests
        // Add more ...
        super.onCreate(instrumentationArguments);
    }
}

然后在你的 build.gradle 设置 testInstrumentationRunner (这是在 Android的 - &GT; defaultConfig ,即

// ...

android {
    // ...

    defaultConfig {
        // ...
        testInstrumentationRunner "com.my.package.MyInstrumentationTestRunner"
    }
}

// ...

希望它能帮助!

请注意。 build.gradle :LIB ,测试都位于的src / androidTest / java的其中 MyInstrumentationTestRunner 创建。

Hope it helps!

Note. build.gradle is from :lib, the tests are located under src/androidTest/java where the MyInstrumentationTestRunner is created.

这篇关于我怎样才能运行一组特定的与Android的摇篮仪器测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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