1

This answer describes a way to run a specific espresso test:

./gradlew app:connectedAndroidTest -Pandroid.testInstrumentationRunnerArguments.class=com.my.tests.MyTest

But I would like to create a gradle task to run it like this:

./gradlew app:runMyTest

But when I try to define runMyTest task:

task runMyTest {
    finalizedBy connectedDAT

    project.extensions.add("android.testInstrumentationRunnerArguments.class", "com.my.tests.MyTest")
}

and run it, all my tests run, not only the specified one.

netimen
  • 4,199
  • 6
  • 41
  • 65

1 Answers1

0

You can do something like this,

apply plugin: 'java'

test {
  filter {
      //specific test method
      includeTestsMatching "com.yourpackage.YourTest"
  }
}

or check the sample code below and work something out,

sourceSets {

  integration {
    java.srcDir 'src/test/integration/java'
    resources.srcDir 'src/test/resources'
    compileClasspath += main.output + test.output
    runtimeClasspath += main.output + test.output
  }

}

configurations {
  integrationCompile.extendsFrom testCompile
  integrationRuntime.extendsFrom testRuntime
}

task integration(type: Test, description: 'Runs the integration tests.', group: 'Verification') {
  testClassesDir = sourceSets.integration.output.classesDir
  classpath = sourceSets.integration.runtimeClasspath
}
Basim Sherif
  • 5,384
  • 7
  • 48
  • 90