Performing measurement tests from a special package through the gradle plugin

I use spoon-gradle-plugin from Roman Mazur. I can run all tests at the same time, but it’s hard for me to specify a “group” of tests that I would like to run. Currently, my spoon setup looks like this:

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 in packages:

enter image description here

And my goal is to create separate spoon-dependent gradle tasks to run tests from each package separately. The novel gave us the instrumentationArgs parameter, which should be able to edit some properties inside the spoon.

As I can see on the main git spoons , it is written that you can specify the package in which your tests should look for the tepher and the example looks like this:

 --e package=com.mypackage.unit_tests 

So my idea was to put this property in instrumentationArgs. Therefore, I created my tasks with a spoon:

 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; } } 

What I can say is that the noAnimations parameter perfectly complements the default spoon configuration, preventing the creation of gifs. So InstrumentArgs will probably accept my string array, but will not apply this 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, what am I doing with the "package" property, I always get the result:

 -e package com.myapp.instrumentation.flowtests 

And I want to change it, but I don’t know how to do it. In addition, I can say that I tried to find the line in the project line "com.myapp.instrumentation.flowtests", and its only places are: tests in the package + gradle tasks presented above. So it is not encoded anywhere. The same location is selected if I run tests with:

 ./gradlew spoon 

And after I use:

 ./gradlew spoonAuthFlowTests 

It also runs the entire test suite.

+4
source share
1 answer

Your problem is that you are misinterpreting how the spoon block works in your Gradle configuration. When you write something like

 spoon { debug = true } 

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

Therefore, when you call spoon {} inside your task definitions, you simply override the existing values. And the last values ​​apply.

If you want to create your own 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. } 

You can see all the properties of the tasks in SpoonRunTask Sources . Most of them are installed from this single configuration object by the plugin when it creates its tasks.

If this sounds too complicated, you can choose another method. Customize your arguments using project properties that can be defined on the command line.

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

Now you can run

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

Therefore, instead of specifying various tasks on the command line, you will specify different project properties.

The downside is that you won’t be able to run tests for 2 packages with one Gradle call. You will have to call it twice with different values.

+4
source

Source: https://habr.com/ru/post/1234291/


All Articles