2017-09-03 90 views
0

我目前正在尝试使用此库在android上运行ui测试。对目录的根目录如何运行取决于测试任务的定制gradle插件

./gradlew verifyMode screenshotTests 

https://github.com/facebook/screenshot-tests-for-android

我使用运行测试。

然而,所有我想运行是:

./gradlew test 

而且我想它运行的截图测试以及我的UI测试。这可能是待办事项吗?我当前的构建文件:

buildscript { 
    repositories { 
     jcenter() 
     mavenLocal() 
     mavenCentral() 
    } 

    dependencies { 
     classpath 'com.android.tools.build:gradle:2.2.0' 
     classpath 'com.facebook.testing.screenshot:plugin:0.4.2' 
    } 
} 

apply plugin: 'com.android.application' 
apply plugin: 'com.facebook.testing.screenshot' 

android { 
    compileSdkVersion 24 
    buildToolsVersion '24.0.3' 

    defaultConfig { 
     applicationId "sample" 
     minSdkVersion 16 
     targetSdkVersion 22 
     versionCode 1 
     versionName "1.0" 
     testInstrumentationRunner "sample.TestRunner" 
    } 
    buildTypes { 
     release { 
      minifyEnabled false 
      proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 
     } 
    } 
} 

dependencies { 
    compile fileTree(include: ['*.jar'], dir: 'libs') 
    compile 'com.android.support:appcompat-v7:24.2.1' 
    compile 'com.android.support:support-v4:24.2.0' 
    compile project(':library') 
    androidTestCompile 'com.android.support.test:runner:0.4' 
    androidTestCompile 'com.azimolabs.conditionwatcher:conditionwatcher:0.1' 
    androidTestCompile 'com.android.support.test:rules:0.4' 
    androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.1' 
    androidTestCompile 'com.google.dexmaker:dexmaker-mockito:1.0' 
    androidTestCompile 'com.google.dexmaker:dexmaker:1.0' 
    androidTestCompile 'org.mockito:mockito-core:1.10.17' 
    androidTestCompile 'com.android.support:support-annotations:24.2.1' 
} 

回答

0

Gradle执行指定为命令行参数及其依赖关系的任务。如果你只是想指定您的命令test任务,但仍执行任务verifyModescreenshotTests,可以将这些任务作为test任务的依赖性登记:

test { 
    dependsOn 'verifyMode', 'screenshotTests' 
} 

但是,请注意,现在每次执行test任务也将导致verifyModescreenshotTests及其各自的依赖关系运行。由于test任务是build任务的依赖项,因此调用gradle build还将运行verifyModescreenshotTests,这可能不是您想要的。作为一个解决方案,你可以定义一个虚拟任务,收集所有的测试任务:

task allTests { 
    dependsOn 'test', 'verifyMode', 'screenshotTests' 
} 

现在你可以调用gradle allTests和摇篮将执行只是要执行的任务。

相关问题