Running instrumentation tests from specific package via spoon-gradle plugin

懵懂的女人 提交于 2019-12-05 15:59:14

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

spoon {
  debug = true
}

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

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

Now you can run

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

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!