How to setup the robolectric in Android Studio -
i doing work test android application using unit framework robolectric
. have installed android studio (.4.6)
all blogs saying "in order able run android unit tests gradle, need add gradle android test plug-in build script."
but deprecated how can setup without using or have use this.
i using com.github.jcandksolutions.gradle:android-unit-test:+
so in 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 app's build.gradle
apply plugin: 'android' android { [...] sourcesets { // sets root test folder src/test overriding 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 have declare dependency twice (one instrumenttestcompile scope , 1 testcompile scope (for android-unit-test plugin)). necessary @ least version of android studio , plugin.
then can run tests gradlew test terminal (either in android studio or standalone).
side note 1: had problems android studio terminal integration on windows. did not handle limited horizontal space available, truncating output. result started using conemu, avoiding embedded terminal in android studio , standard cmd.exe.
Comments
Post a Comment