Git Product home page Git Product logo

robolectric-gradle-plugin's Introduction

Robolectric Gradle Plugin

Build Status

A Gradle plugin which enables Robolectric tests.

Compatibility

Currently compatible with version 0.13.x of the android gradle plugin.

Getting Started

If you are starting a new app, or want to try this plugin in the simplest possible environment, the easiest way to start is to use deckard-gradle.

deckard-gradle illustrates how to run Robolectric and Espresso tests in IntelliJ, Android Studio or the command-line.

Basic Usage for JUnit / Robolectric

Add the plugin to your buildscript's dependencies section:

classpath 'org.robolectric:robolectric-gradle-plugin:0.13.+'

Apply the robolectric plugin:

apply plugin: 'robolectric'

Add test-only dependencies using the androidTestCompile configuration:

androidTestCompile 'org.robolectric:robolectric:2.3'

Place your tests in src/test/java or src/androidTest/java You can also add per-build type and per-flavor tests by using the same folder naming conventions (e.g., src/testPaid/java, src/testDebug/java).

Run your tests by calling gradle clean test.

Configuration using DSL

robolectric {
    // configure the set of classes for JUnit tests
    include '**/*Test.class'
    exclude '**/espresso/**/*.class'

    // configure max heap size of the test JVM
    maxHeapSize = '2048m'

    // configure the test JVM arguments
    jvmArgs '-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 build
    ignoreFailures true

    // use afterTest to listen to the test execution results
    afterTest { descriptor, result ->
        println "Executing test for {$descriptor.name} with result: ${result.resultType}"
    }
}

Importing into your IDE (IntelliJ or Android Studio)

In a nutshell, you should be able to import into these IDEs (and continuously sync when you change your build.gradle).

It bears repeating, though: if you see the dreaded Stub! exception:

!!! JUnit version 3.8 or later expected:

java.lang.RuntimeException: Stub!
at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
at junit.textui.TestRunner.<init>(TestRunner.java:54)
at junit.textui.TestRunner.<init>(TestRunner.java:48)
at junit.textui.TestRunner.<init>(TestRunner.java:41)

...you will have to hand-edit your dependencies (in the IDE for IntelliJ, or hand-editing your IML file in Studio). See deckard-gradle for details.

License

Copyright 2013 Square, Inc.
          2014 Pivotal Labs

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.