Robolectric Gradle plugin

A custom robolectric plugin that gives full control on Gradle Test.

License

License

Categories

Categories

Gradle Build Tools
GroupId

GroupId

com.github.vignesh-iopex
ArtifactId

ArtifactId

robolectric-gradle-plugin
Last Version

Last Version

0.3.0
Release Date

Release Date

Type

Type

jar
Description

Description

Robolectric Gradle plugin
A custom robolectric plugin that gives full control on Gradle Test.
Project URL

Project URL

https://github.com/vignesh-iopex/robolectric-gradle-plugin
Source Code Management

Source Code Management

https://github.com/vignesh-iopex/robolectric-gradle-plugin

Download robolectric-gradle-plugin

How to add to project

<!-- https://jarcasting.com/artifacts/com.github.vignesh-iopex/robolectric-gradle-plugin/ -->
<dependency>
    <groupId>com.github.vignesh-iopex</groupId>
    <artifactId>robolectric-gradle-plugin</artifactId>
    <version>0.3.0</version>
</dependency>
// https://jarcasting.com/artifacts/com.github.vignesh-iopex/robolectric-gradle-plugin/
implementation 'com.github.vignesh-iopex:robolectric-gradle-plugin:0.3.0'
// https://jarcasting.com/artifacts/com.github.vignesh-iopex/robolectric-gradle-plugin/
implementation ("com.github.vignesh-iopex:robolectric-gradle-plugin:0.3.0")
'com.github.vignesh-iopex:robolectric-gradle-plugin:jar:0.3.0'
<dependency org="com.github.vignesh-iopex" name="robolectric-gradle-plugin" rev="0.3.0">
  <artifact name="robolectric-gradle-plugin" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.github.vignesh-iopex', module='robolectric-gradle-plugin', version='0.3.0')
)
libraryDependencies += "com.github.vignesh-iopex" % "robolectric-gradle-plugin" % "0.3.0"
[com.github.vignesh-iopex/robolectric-gradle-plugin "0.3.0"]

Dependencies

compile (1)

Group / Artifact Type Version
com.android.tools.build : gradle jar 1.0.0-rc1

test (2)

Group / Artifact Type Version
junit : junit jar 4.10
org.assertj : assertj-core jar 1.7.0

Project Modules

There are no modules declared in this project.

Robolectric Gradle Plugin

Build Status

A Gradle plugin which enables Robolectric tests.

Compatibility

Currently compatible with version 0.12.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.12.+'

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 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.

Versions

Version
0.3.0
0.2.0
0.1.1