mercadolibre/robolectric

Name: robolectric

Owner: MercadoLibre

Description: Android Unit Testing Framework

Created: 2016-06-16 17:43:22.0

Updated: 2016-06-16 17:43:25.0

Pushed: 2016-08-10 20:17:58.0

Homepage: http://robolectric.org

Size: 27956

Language: Java

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Build Status

Robolectric is a testing framework that de-fangs the Android SDK so you can test-drive the development of your Android app.

Usage

Here's an example of a simple test written using Robolectric:

With(RobolectricGradleTestRunner.class)
fig(constants = BuildConfig.class)
ic class MyActivityTest {

est
blic void clickingButton_shouldChangeResultsViewText() throws Exception {
Activity activity = Robolectric.setupActivity(MyActivity.class);

Button button = (Button) activity.findViewById(R.id.press_me_button);
TextView results = (TextView) activity.findViewById(R.id.results_text_view);

button.performClick();
assertThat(results.getText().toString(), equalTo("Testing Android Rocks!"));


For more information about how to install and use Robolectric on your project, extend its functionality, and join the community of contributors, please visit http://robolectric.org.

Install
Starting a New Project

If you'd like to start a new project with Robolectric you can use deckard (for either maven or gradle). These project will guide you through setting up both Android and Robolectric on your machine.

Gradle
Compile "org.robolectric:robolectric:3.1"
Maven
endency>
groupId>org.robolectric</groupId>
artifactId>robolectric</artifactId>
version>3.1</version>
scope>test</scope>
pendency>
Building And Contributing

Robolectric is built using Maven. Both Eclipse (with the M2Eclipse plug-in) and IntelliJ can import the pom.xml file and will automatically generate their project files from it. You will need to have portions of the Android SDK available in your local Maven repo in order to build Robolectric.

Mavenize all required dependencies by running:

./scripts/install-dependencies.rb

Because Robolectric's shadows are compiled against the Android APIs that they target, you must build the shadows for all API levels before being able to run any of the tests. You can build all of Robolectric by running:

./scripts/install-robolectric.sh

After doing this once, you can build and test against the specific API level you care about:

mvn install -P android-18 (for example)
Using Snapshots

If you would like to live on the bleeding edge, you can try running against a snapshot build. Keep in mind that snapshots represent the most recent changes on master and may contain bugs.

Gradle
sitories {
maven { url "https://oss.sonatype.org/content/repositories/snapshots" }


ndencies {
testCompile "org.robolectric:robolectric:3.2-SNAPSHOT"

Maven
ository>
d>sonatype-snapshpots</id>
rl>https://oss.sonatype.org/content/repositories/snapshots</url>
pository>

endency>
groupId>org.robolectric</groupId>
artifactId>robolectric</artifactId>
version>3.2-SNAPSHOT</version>
scope>test</scope>
pendency>

This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.