从特定的包通过匙插件的gradle运行测试仪器 [英] Running instrumentation tests from specific package via spoon-gradle plugin

查看:371
本文介绍了从特定的包通过匙插件的gradle运行测试仪器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用从罗马马祖尔勺子gradle这个-插件。我能同时运行所有测试,但我有麻烦的,我想推出测试指定组。目前我的勺子的设置是这样的:

I am using spoon-gradle-plugin from Roman Mazur. I am capable of running all tests at once but I am having trouble to specify "group" of tests that I would like to launch. Currently my spoon setup looks like that:

spoon {
    debug = true

    baseOutputDir = file("$buildDir/spoon-log")
    if (project.hasProperty('spoonClassName')) {
        className = project.spoonClassName

        if (project.hasProperty('spoonMethodName')) {
            methodName = project.spoonMethodName
        }
    }

    adbTimeout = 60 * 60;
}

我的测试中位于包:

My tests are located in packages:

在这里输入的形象描述

和我的目标是创建一个是取决于勺子从每包分别发射试验的gradle独立的任务。罗马给我们的参数<一个href=\"https://github.com/stanfy/spoon-gradle-plugin/blob/master/src/main/groovy/com/stanfy/spoon/gradle/SpoonExtension.groovy\"相对=nofollow> instrumentationArgs 这应该是能够编辑勺子中的某些属性。

And my goal is to create separate gradle tasks that are depending on spoon to launch tests from each package separately. Roman gave us parameter instrumentationArgs which should be capable of editing some properties within the spoon.

我可以在勺主要混帐看到有写,你可以指定包,其中勺子-runner应该寻找你的测试和例子是这样的:

As I can see on main git of spoon there is written that you can specify package, where spoon-runner should look for your tests and example goes like that:

--e package=com.mypackage.unit_tests

所以我的想法是把这个属性为instrumentationArgs。因此我创造了我的勺子任务像:

So my idea was to put this property into instrumentationArgs. Consequently I created my spoon tasks like that:

task spoonAuthFlowTests(type: GradleBuild, dependsOn: ['spoon']) {
    spoon {
        instrumentationArgs = ["package=com.myapp.instrumentation.flowtests.AuthFlowTests"]
        noAnimations = true;
    }
}

task spoonFlowTests(type: GradleBuild, dependsOn: ['spoon']) {
    spoon {
        instrumentationArgs = ["package=com.myapp.instrumentation.flowtests"]
        noAnimations = true;
    }
}

我只能说那是什么noAnimations参数是很好的扩展默认配置勺子,从创建preventing GIF格式。所以instrumentationArgs可以肯定的是把我的字符串数组,而是因为在我的终端不应用更改:

What can I say is that noAnimations parameter is nicely extending default spoon config, preventing gifs from being created. So instrumentationArgs is for sure taking my string array, but doesn't apply the change because in my terminal:

2016-01-08 15:13:10 [SDR.run] About to actually run tests for [04ffe19ad317d2e7]
03:13:10 I/RemoteAndroidTest: Running am instrument -w -r   -e package com.myapp.instrumentation.flowtests -e class com.myapp.instrumentation.flowtests.AuthFlowTests.LoginUserFlowTests com.myapp.debug1.test/com.myapp.instrumentation.helper.runner.MyAppTestRunner on lge-nexus_4-04ffe19ad317d2e7

没有什么奥美与我一揽子财产做什么,我总是收到结果是:

No mather what I do with "package" property, I always receive result:

-e package com.myapp.instrumentation.flowtests

和我想改变它,但不知道怎么办。此外,我可以说,我想看看在我的项目com.myapp.instrumentation.flowtests字符串,它是唯一使用的位置是:在包+ gradle这个任务$ P $测试上方psented。所以,不难codeD的任何地方。如果我开始通过试验相同的位置选择的是:

And I want to change it, but don't know how. Furthermore I can say that I tried to look up in my project "com.myapp.instrumentation.flowtests" string and the only locations where it is used are: tests in package + gradle tasks presented above. So it isn't hardcoded anywhere. Same location is picked if I start tests by:

./gradlew spoon

后,我用:

./gradlew spoonAuthFlowTests

它还可以运行整个测试集。

It also runs whole test set.

推荐答案

您的问题是,你不正确间preT如何勺子块的工作在你的摇篮配置。
当你写的东西像

Your problem is that you incorrectly interpret how spoon block works in your Gradle config. When you write something like

spoon {
  debug = true
}

您基本修改与您的摇篮项目相关的单独的对象。该项目包含由勺子插件创建的所有任务之间共享的配置。
勺子插件创建为您的项目定义(这样就可以单独运行针对每种口味测试)不同的口味不同的任务。也有像 spoonSmall spoonMedium 任务运行与 @Small @Medium 而已。
所有这些任务使用您修改同一个配置对象勺{}

You basically modify a singleton object associated with your Gradle project. This project contains a configuration shared between all the tasks created by the spoon plugin. Spoon plugin creates separate tasks for different flavors defined in your project (so that you can run tests for each flavour separately). Also there are tasks like spoonSmall, spoonMedium to run tests annotated with @Small or @Medium only. All these tasks use the same configuration object you alter with spoon {}.

因此​​,当你调用勺{} 你的任务定义中您只需重写现有值。而最后的值被应用。

Hence, when you call spoon {} inside of your tasks definitions you simply override existing values. And the last values are applied.

如果你想创建一个自定义的勺子亚军任务,你应该写类似

If you want to create a custom spoon runner task, you should write something like

import com.stanfy.spoon.gradle.SpoonRunTask
task spoonAuthFlowTests(type: SpoonRunTask) {
  instrumentationArgs = ['package=com.myapp.instrumentation.flowtests.AuthFlowTests']
  // But you will have to set many other options on the tasks,
  // like instrumentationApk and applicationApk files.
}

您可以看到<一个所有任务的属性href=\"https://github.com/stanfy/spoon-gradle-plugin/blob/v1.0.4/src/main/groovy/com/stanfy/spoon/gradle/SpoonRunTask.groovy#L33-L75\"相对=nofollow> SpoonRunTask来源的。他们多数是从单一的配置对象<一集href=\"https://github.com/stanfy/spoon-gradle-plugin/blob/v1.0.4/src/main/groovy/com/stanfy/spoon/gradle/SpoonPlugin.groovy#L98\"相对=nofollow>由插件时,它会创建任务。

You can see all the tasks properties in SpoonRunTask sources. Majority of them are set from that single configuration object by the plugin when it creates its tasks.

如果这听起来太复杂,你可以选择不同的方式。使用可以在命令行中定义的项目属性来配置你的论点。

If this sounds too complicated, you can choose a different way. Configure your arguments using project properties that can be defined in command line.

spoon {
  instrumentationArgs = ["package=${project.getProperty('spoonPackage')}"]
  noAnimations = true;
}

现在可以运行

./gradlew spoon -PspoonPackage=com.myapp.instrumentation.flowtests

所以

而不是在命令行指定不同的任务,你会被指定不同的项目属性。

So instead of specifying different tasks in the command line you will be specifying different project properties.

缺点是,你将不能够为2包一个调用的gradle运行测试。你将不得不使用不同的值两次调用它。

The downside is that you will not be able to run tests for 2 packages with one gradle invocation. You will have to call it twice with different values.

这篇关于从特定的包通过匙插件的gradle运行测试仪器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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