robolectric/robolectric


Android Unit Testing Framework

http://robolectric.org

License: MIT

Language: Java

Keywords: android, java, robolectric, unit-testing


Build Status GitHub release

Robolectric is the industry-standard unit testing framework for Android. With Robolectric, your tests run in a simulated Android environment inside a JVM, without the overhead of an emulator.

Usage

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

@RunWith(RobolectricTestRunner.class)
public class MyActivityTest {

  @Test
  public 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 tests you can refer to deckard (for either maven or gradle) as a guide to setting up both Android and Robolectric on your machine.

build.gradle:

testImplementation "org.robolectric:robolectric:4.1"

Building And Contributing

Robolectric is built using Gradle. Both IntelliJ and Android Studio can import the top-level build.gradle 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 artifact repository in order to build Robolectric. Copy all required Android dependencies to your local Maven repo by running:

./scripts/install-dependencies.rb

Note: You'll need Maven installed, ANDROID_HOME set and to have the SDK and Google APIs for API Level 27 downloaded to do this.

Robolectric supports running tests against multiple Android API levels. The work it must do to support each API level is slightly different, so its shadows are built separately for each. To build shadows for every API version, run:

./gradlew clean assemble install compileTest

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.

build.gradle:

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

dependencies {
    testImplementation "org.robolectric:robolectric:4.2-SNAPSHOT"
}

Project Statistics

Sourcerank 17
Repository Size 41.2 MB
Stars 4,359
Forks 1,154
Watchers 229
Open issues 456
Dependencies 145
Contributors 304
Tags 89
Created
Last updated
Last pushed

Top Contributors See all

Christian Williams Jonathan Gerrish brettchabot Erich Douglass a-googler Jake Wharton Jan Berkel Chris Van Vranken Tyler Schultz rdh Fr Jeremy Krieg Michael Hoisie Nikolas Bravo Roman Mazur Michael Portuesi Corey Downing Alexander Blom rjrjr Patrick Forhan Callum Stott

Packages Referencing this Repo

org.robolectric:processor
An alternative Android testing framework.
Latest release 4.0-alpha-3 - Updated - 4.36K stars
org.robolectric:shadows-framework
An alternative Android testing framework.
Latest release 4.0-alpha-2 - Updated - 4.36K stars
org.robolectric:shadows-supportv4
An alternative Android testing framework.
Latest release 4.0-alpha-2 - Updated - 4.36K stars
org.robolectric:shadow-api
An alternative Android testing framework.
Latest release 3.4-rc2 - Updated - 4.36K stars
org.robolectric:shadows-support-v4
An alternative Android testing framework.
Latest release 3.4-rc2 - Updated - 4.36K stars
org.robolectric:utils
An alternative Android testing framework.
Latest release 4.1 - Updated - 4.36K stars
org.robolectric:robolectric
An alternative Android testing framework.
Latest release 4.0-alpha-2 - Updated - 4.36K stars
org.robolectric:robolectric-shadows
Android Unit Testing Framework
Latest release 3.1 - Updated - 4.36K stars
com.pivotallabs:robolectric
An alternative Android testing framework.
Latest release 1.2 - Updated - 4.36K stars
org.robolectric:maps
An alternative Android testing framework.
Latest release 3.4.2 - Updated - 4.36K stars
org.robolectric:robolectric-annotations
Annotations used by the Robolectric testing framework.
Latest release 3.4-rc2 - Updated - 4.36K stars
org.robolectric:parent
An alternative Android testing framework.
Latest release 3.1.4 - Updated - 4.36K stars
org.robolectric:playservices
An alternative Android testing framework.
Latest release 3.4.2 - Updated - 4.36K stars
org.robolectric:resources
An alternative Android testing framework.
Latest release 4.0-alpha-2 - Updated - 4.36K stars
org.robolectric:junit
An alternative Android testing framework.
Latest release 4.0-alpha-3 - Updated - 4.36K stars
org.robolectric:annotations
An alternative Android testing framework.
Latest release 4.0-alpha-2 - Updated - 4.36K stars
org.robolectric:robolectric-sandbox
An alternative Android testing framework.
Latest release 3.4-rc2 - Updated - 4.36K stars
org.robolectric:robolectric-junit
An alternative Android testing framework.
Latest release 3.4-rc2 - Updated - 4.36K stars
org.robolectric:robolectric-utils
An alternative Android testing framework.
Latest release 3.4-rc2 - Updated - 4.36K stars
org.robolectric:shadows-multidex
An alternative Android testing framework.
Latest release 4.0-alpha-2 - Updated - 4.36K stars

Recent Tags See all

robolectric-4.2-alpha-2 February 01, 2019
robolectric-4.2-alpha-1 January 24, 2019
robolectric-4.1 December 12, 2018
robolectric-4.1-beta-2 December 07, 2018
robolectric-4.1-beta-1 December 07, 2018
robolectric-4.1-alpha-1 November 30, 2018
robolectric-4.0.2 November 10, 2018
robolectric-4.0.1 October 31, 2018
robolectric-4.0 October 25, 2018
robolectric-4.0-beta-3 October 25, 2018
robolectric-4.0-beta-2 October 23, 2018
robolectric-4.0-beta-2 October 23, 2018
robolectric-3.6.2 October 11, 2018
robolectric-3.6.2 October 11, 2018
robolectric-4.0-beta-1 October 05, 2018

Interesting Forks See all

facebook/robolectric
Android Unit Testing Framework
Java - MIT - Last pushed - 38 stars - 13 forks
BCGDV/robolectric
Android Unit Testing Framework
Java - MIT - Last pushed - 2 stars - 3 forks
g3global/robolectric
Android Unit Testing Framework
Java - MIT - Last pushed - 2 stars - 1 forks
magun/robolectric
Android Unit Testing Framework
Java - MIT - Updated - 2 stars - 1 forks
shazam/robolectric
Android Unit Testing Framework
Java - MIT - Last pushed - 2 stars - 2 forks

Something wrong with this page? Make a suggestion

Last synced: 2019-02-01 14:43:06 UTC

Login to resync this repository