Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'./gradlew -Dtest.single=SimpleTest test' runs all tests I have

My project is normal Android project created on Android Studio.

project structure

I googled a lot to run a single test(tests in SimpleTest, 1 test in this case), everyone say that I should do like

./gradlew -Dtest.single=SimpleTest test

in my root folder.

or I did in my inner project folder

../gradlew -Dtest.single=SimpleTest test

I tried so many ways like this but it always run all tests I have.(11 tests in all Classes)

Is there a problem on my build.gradle or is there a something I missing?

Here is my build.gradle file.

buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'com.android.tools.build:gradle:0.6.+'

        classpath 'com.github.jcandksolutions.gradle:android-unit-test:1.0.+'
    }
}

apply plugin: 'android'

    repositories {
        mavenCentral()
    }

android {
    compileSdkVersion 18
    buildToolsVersion "18.1.1"

    defaultConfig {
        minSdkVersion 10
        targetSdkVersion 18
        // I changed this for this question
        packageName "com.XXX.XXXX"
    }

    sourceSets {
        instrumentTest.setRoot('src/test')
    }
}

apply plugin: 'android-unit-test'

dependencies {
    repositories {
        mavenCentral()
    }
    compile 'com.android.support:support-v4:18.0.+'
    compile 'com.android.support:appcompat-v7:+'

    compile 'com.google.code.gson:gson:2.2.4'
    compile group:'com.squareup.picasso', name:'picasso', version:'2.1.1'
    compile group:'com.squareup.okhttp', name:'okhttp', version:'1.2.1'
    compile group:'com.squareup', name:'otto', version:'1.3.4'

    compile group:'com.jakewharton', name:'butterknife', version:'3.0.0'

    compile group:'com.github.kevinsawicki', name:'http-request', version:'5.4.1'

    compile fileTree(dir: 'libs', include: '*.jar')

    testCompile 'junit:junit:4.10'
    testCompile 'org.robolectric:robolectric:2.2'
    testCompile 'com.squareup:fest-android:1.0.+'

    instrumentTestCompile 'junit:junit:4.10'
    instrumentTestCompile 'org.robolectric:robolectric:2.2'
    instrumentTestCompile 'com.squareup:fest-android:1.0.+'
}

tasks.withType(Compile) {
    options.encoding = "UTF-8"
}

tasks.withType(Test) {
    testLogging {
        events 'started', 'passed'
    }
}
like image 636
Wooseong Kim Avatar asked Nov 07 '13 01:11

Wooseong Kim


2 Answers

this is what worked for me:

./gradlew testDebug --tests *TaskCommandSpec

Use testDebug or testRelease instead of just test. If you have build variants then use e.g testProRelease

docs: https://docs.gradle.org/current/userguide/userguide_single.html

like image 71
zack Avatar answered Sep 27 '22 20:09

zack


The notation

-Dtest.single=SimpleTest

means that in the task named 'test' run only SimpleTest. If your test task name differs you have to change the system property. E.g. your test task is named 'instrumentationTest' the property must be

-DinstrumentationTest.single=SimpleTest

cheers, René

like image 30
Rene Groeschke Avatar answered Sep 27 '22 21:09

Rene Groeschke