Add Robolectric with Gradle in Android studio

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.