We use robolectric test words need to be configured in Gradle, the domestic detailed tutorial is too simple, and many are low version of the configuration scheme. So after my careful groping, found the current high version of the configuration plan, mainly refer to the official website Configuration tutorial:Https://github.com/robolectric/robolectric-gradle-plugin
The following is a complete set of steps, after reading it can be configured successfully ~
The following Scarlet Letter section is the part you want to add.
First, configure the classpath in the outermost build.gradle
// top-level build file where can add configuration options common to all sub-projects/modules. Buildscript { repositories { jcenter () mavencentral () } dependencies { ' com.android.tools.build:gradle:1.1.0 ' classpath ' org.robolectric:robolectric-gradle-plugin:1.0.1 ' // Note:do not place your application dependencies here; they belong // In the individual module build.gradle files }}allprojects { repositories { jcenter () mavencentral ()} }
The following configuration is then performed in the Build.gradle of the project (3 sections):
Apply plugin: ' Com.android.application '//1.test PluginApply plugin: ' Org.robolectric 'Android {compilesdkversion22buildtoolsversion"22.0.1"Defaultconfig {ApplicationID"KALE.ANDROIDMVP"minsdkversion16targetsdkversion22Versioncode1Versionname"1.0"} buildtypes {release {minifyenabledfalseproguardfiles Getdefaultproguardfile (' Proguard-android.txt '), ' Proguard-rules.pro '}}}dependencies {compile Filetree (dir:' Libs ', include: [' *.jar ']) Compile' com.android.support:appcompat-v7:22.1.1 '//2. Test-libs androidtestcompile ' junit:junit:4.12 ' androidtestcompile ' org.robolectric:robolectric:2.4 '}//3. Test SettingsRobolectric { //Configure includes/excludesInclude ' **/*test.class 'Exclude' **/espresso/**/*.class '//Configure Max Heap size of the test JVMmaxheapsize = ' 2048m '//Configure the test JVM arguments-does not apply to Java 8Jvmargs '-xx:maxpermsize=512m ', '-xx:-usesplitverifier '//specify max number of processes (default is 1)Maxparallelforks = 4//Specify max number of test classes to execute in a test process//before restarting the process (default is unlimited)Forkevery = 150//Configure whether failing tests should fail the buildIgnorefailurestrue //Use Aftertest to listen to the test execution ResultsAftertest {descriptor, result-println"Executing test for ${descriptor.name} with result: ${result.resulttype}" }}
Reference from:
http://blog.yohei.org/android-studio-gradle-robolectric1/
Https://github.com/robolectric/robolectric-gradle-plugin
Add Robolectric with Gradle in Android studio