如何创建运行特定espresso测试的gradle任务

时间:2018-05-17 15:37:48

标签: android gradle android-espresso

This answer描述了运行特定espresso测试的方法:

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

但是我想创建一个gradle任务来运行它:

./gradlew app:runMyTest

但是当我尝试定义runMyTest任务时:

task runMyTest {
    finalizedBy connectedDAT

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

并运行它,我的所有测试都运行,而不仅仅是指定的测试。

1 个答案:

答案 0 :(得分:0)

你可以这样做,

apply plugin: 'java'

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

或查看下面的示例代码并解决问题,

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
}