Search code examples
android-gradle-plugingradle-plugingradle-kotlin-dsl

How to pass argument from Gradle Plugin to JUnit4 Test Runner?


I have access to some variables across multiple projects via a shared Gradle Plugin, and I would like to pass an argument to my test runner from the plugin.

For example, via adb shell, the argument would look like this:

$ adb shell am instrument -e myarg MYARG com.example.my.test/.MyTestRunner -w

Is there a way I could emulate the -e myarg MYARG behaviour from Gradle Plugin code?

(Any equivalent approach would an accepted answer though - I just need a way to pass a variable value accessible in my plugin to my Test Runner)

Thank you!


Solution

  • The answer is to set a defaultConfig.TestInstrumentationRunnerArgument value, along with your Test Runner and listener. So in our plugin code, we have:

    defaultConfig.testInstrumentationRunner = "com.mypackage.MyTestRunnerClassName"
    defaultConfig.testInstrumentationRunnerArgument("listener", "com.mypackage.MyTestListenerClassName")