My project is normal Android project created on Android Studio.
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'
}
}
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
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é
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With