lundi 21 septembre 2015

How to run specific test using using gradlew on command line?

I'm quite new with the Android gradle build. I built and application and it work quite ok. Now I would like to add unit test and instrument test into it, and execute them on command line.

I have to test files:

  • MainActivityTest.java <== This used instrumentation test which should be executed on a device.
  • CustomerFragmentTest.java <== This used junit test which should be executed on JVM only.

Now from the command line in Project Directory I called

gradlew test --continue

And it executed all tests (both JVM tests and Device Tests) while I expect only the JVM tests to be run.

So:

  1. How can I run the junit test cases on JVM only (Ignore the instrumentation test cases)?
  2. When I call gradlew connectedTest I got the execution failed message:

    "Task 'connectedTest' not found in root project'Android5Camera'"

    How can I execute the instrumentation tests (on Device) using command line?

Thank for any help and advice.

Here by my app.gradle config in case you need:

apply plugin: 'com.android.application'

android {
    compileSdkVersion 22
    buildToolsVersion "22.0.1"

    defaultConfig {
        applicationId "com.huynhle.android5camera"
        minSdkVersion 16
        targetSdkVersion 22
        testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
        versionCode 1
        versionName "1.0"
    }
    buildTypes {
        release {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
        }
    }

    sourceSets {
        main {
            java.srcDirs = ['src/main/java']
        }
        main.setRoot('src/main')
        androidTest.setRoot('src/test')
    }
}

dependencies {

    compile fileTree(dir: 'libs', include: ['*.jar'])
    compile 'com.android.support:appcompat-v7:22.2.0'
    compile 'com.astuetz:pagerslidingtabstrip:1.0.1'

    testCompile 'junit:junit:4.12'
    testCompile 'org.mockito:mockito-core:1.10.19'

    androidTestCompile 'com.android.support.test:runner:0.3'
    androidTestCompile 'com.android.support.test:rules:0.3'
}

Aucun commentaire:

Enregistrer un commentaire