有没有一种方法只运行一组特定的测试,在Android摇篮的项目? [英] Is there a way to only run a specific set of tests in an Android Gradle project?

查看:187
本文介绍了有没有一种方法只运行一组特定的测试,在Android摇篮的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android /摇篮工程。每当我想运行测试,我运行:

I have an Android/Gradle project. Whenever I want to run tests, I run:

./gradlew connectedInstrumentTest

它运行在我的项目的测试文件夹,我的所有测试。

which runs all my tests under the test folder of my project.

我的测试文件夹中有多个自动化测试以及非自动化的测试。我最感兴趣的是不慢的自动化测试运行速度快的非自动化的测试。

My test folder has several automation tests as well as non-automation tests. I'm mostly interested in running the fast non-automation tests without the slow automation tests.

有没有办法只运行一组特定的测试,例如从一个特定的类或任何类似?我基本上问任何分割,这样我就可以选择只运行一些测试时,我想。

Is there a way to run just a specific set of tests, such as from one specific class or anything similar? I'm basically asking about any kind of separation so that I can choose to run just a few tests when I want to.

创建了一个示例项目这里

修改 local.properties 来指向您的Andr​​oid SDK。

Edit local.properties to point at your Android SDK.

接下来,启动仿真器或手机连接到您的计算机。然后,你可以使用运行测试 ./ gradlew connectedInstrumentTest --info 。这将运行所有测试。

Next, start up an emulator or connect a phone to your computer. Then you can run tests using ./gradlew connectedInstrumentTest --info. This runs all tests.

什么我无法弄清楚是如何只运行测试,比方说,有一类,而不是所有的测试。

What I am unable to figure out is how to only run tests in, say, one class and not all tests.

推荐答案

由于Android的摇篮插件1.3.0

从版本开始1.3.0可以(终于!)指定了Android摇篮插件必须通过对参数的 InstrumentationTestRunner

Starting from version 1.3.0 you can (finally!) specify the arguments the Android Gradle Plugin have to pass to the InstrumentationTestRunner.

例如,如果你想运行仅标注了 @SmallTest 测试而忽略其他:

For example, if you want to run only the tests annotated with @SmallTest and ignore the others:

android {
  //....
  defaultConfig {
  //....
    testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
    testInstrumentationRunnerArgument "size", "small"
  }
}


旧的解决方法 此前插件1.3.0是不可能做到这一点,但我已经找到了一点workaound。基本上,我已经标注了 @SmallTest 标注的快速测试和使用的 InstrumentationTestRunner 我是一个自定义子类能够运行只是他们,而不是整个套件。


Old workaround Prior to plugin 1.3.0 is not possible to do that but I've found a little workaound. Basically I've annotated with the @SmallTest annotation the fast tests and using a custom subclass of the InstrumentationTestRunner I'm able to run just them and not the whole suite.

您可以发现,例如:code在这个主旨

You can found the example code in this gist.

这篇关于有没有一种方法只运行一组特定的测试,在Android摇篮的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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