Reputation: 34517
I am doing work to test my android application using unit framework robolectric
. I have installed the Android Studio (.4.6)
All blogs saying for this "In order to be able to run Android unit tests with Gradle, we need to add the Gradle Android Test plug-in to the build script."
but that is deprecated now then how can I setup this without using this or I have to use this.
Upvotes: 1
Views: 1238
Reputation: 5273
I am using com.github.jcandksolutions.gradle:android-unit-test:+
So in your root build.gradle (buildscript section):
repositories {
mavenLocal()
mavenCentral()
maven { url 'https://oss.sonatype.org/content/repositories/snapshots/' }
}
dependencies {
classpath 'com.android.tools.build:gradle:0.8.+'
classpath 'com.github.jcandksolutions.gradle:android-unit-test:+'
}
In your app's build.gradle
apply plugin: 'android'
android {
[...]
sourceSets {
// this sets the root test folder to src/test overriding the default src/instrumentTest
instrumentTest.setRoot('src/test')
}
}
apply plugin: 'android-unit-test'
dependencies {
// example dependencies
instrumentTestCompile 'junit:junit:4.+'
instrumentTestCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
testCompile 'junit:junit:4.+'
testCompile 'org.robolectric:robolectric:2.3-SNAPSHOT'
}
Note that you have to declare the dependency twice (one for instrumentTestCompile scope and one for testCompile scope (for android-unit-test plugin)). This is necessary at least for this version of Android Studio and the plugin.
Then you can run tests with gradlew test from terminal (either in Android Studio or standalone).
Side note 1: I had some problems with Android Studio terminal integration on Windows. It did not handle well the limited horizontal space available, truncating the output. As a result I started using ConEmu, avoiding the embedded terminal in Android Studio and the standard cmd.exe.
Upvotes: 1