Android Unit Testing Framework
Switch branches/tags
robolectric-bazel-3.8 robolectric-4.0.2 robolectric-4.0.1 robolectric-4.0 robolectric-4.0-beta-3 robolectric-4.0-beta-2 robolectric-4.0-beta-1 robolectric-4.0-alpha-3 robolectric-4.0-alpha-2 robolectric-4.0-alpha-1 robolectric-3.9-internal-alpha-0 robolectric-3.8 robolectric-3.7.1 robolectric-3.7 robolectric-3.6.2 robolectric-3.6.1 robolectric-3.6 robolectric-3.6-alpha-1 robolectric-3.5.1 robolectric-3.5 robolectric-3.5-rc1 robolectric-3.4.2 robolectric-3.4.1 robolectric-3.4 robolectric-3.4-rc5 robolectric-3.4-rc4 robolectric-3.4-rc3 robolectric-3.4-rc2 robolectric-3.4-rc1 robolectric-3.3.2 robolectric-3.3.1 robolectric-3.3 robolectric-3.2.2 robolectric-3.2.1 robolectric-3.2 robolectric-3.2-rc1 robolectric-3.1.4 robolectric-3.1.3 robolectric-3.1.2 robolectric-3.1.1 robolectric-3.1 robolectric-3.1-rc1 robolectric-3.0 robolectric-3.0-rc3 robolectric-3.0-rc2 robolectric-3.0-rc1 robolectric-2.4 robolectric-2.3 robolectric-2.2 robolectric-2.1.1 robolectric-2.1 robolectric-2.0 robolectric-2.0-rc2 robolectric-2.0-rc1 robolectric-2.0-alpha-3 robolectric-2.0-alpha-2 robolectric-2.0-alpha-1 robolectric-1.2 robolectric-1.1 robolectric-1.0 robolectric-1.0RC1 robolectric-1.0-RC4 robolectric-1.0-RC3 robolectric-1.0-RC2 robolectric-1.0-RC1 robolectric-0.9.8 robolectric-0.9.7 robolectric-0.9.6 robolectric-0.9.5 _ghsync-base_ beforeAccessChange afterAccessChange Robolectric0_9_4 Robolectric0_9_3 Robolectric0_9_2 Robolectric0_9_1 Robolectric0_9 Robolectric0_8 Release0_9 Release0_8
Nothing to show
Clone or download
Googler and copybara-robolectric Automated g4 rollback of changelist 222103549.
*** Reason for rollback ***

Continuous build failure: https://test.corp.google.com/ui#d=targetZoomout&flags=CAMQBVhg&t=//javatests/com/google/vr/vrcore/compositor/performance:performance_overlay_test

*** Original change description ***

[4146-fix-NoClassDefFound-EGLContext] 4146 - handle all 'javax.microedition.khronos.*' packages (PR#4168)

Closes #4146.
@xian @jongerrish

Pull Request: #4168

Commits:
----
df49f4d - Jared Burrows <jaredsburrows@gmail.com> - 2018-11-17T12:16:41-08:00
    4146 - handle all 'javax.microedition.khronos.*' packages

***

PiperOrigin-RevId: 222135482
Latest commit b584b62 Nov 19, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
.circleci Internal change Sep 5, 2018
.github Update ISSUE_TEMPLATE.md Sep 7, 2017
annotations Clean up warnings and noise. Nov 15, 2018
buildSrc Use ASM 7.0 to support class bytecode version 12 and Java 10+. Nov 8, 2018
errorprone Fix bug checker links. Nov 13, 2018
gradle/wrapper 4075 - update android gradle plugin to 3.2.1 Nov 5, 2018
images Add Robolectric logo to README. Jan 7, 2015
integration_tests Add CTEsque test for KeyCharacterMap. Nov 17, 2018
junit Internal Change. Oct 15, 2018
processor Include shadows for classes that are missing from the SDK in Shadows.… Oct 25, 2018
resources Merge pull request #4132 from robolectric:cleanup-warnings Nov 15, 2018
robolectric Automated g4 rollback of changelist 222103549. Nov 19, 2018
sandbox Automated g4 rollback of changelist 222103549. Nov 19, 2018
scripts Clean up scripts. Nov 12, 2018
shadowapi Clean up warnings and noise. Nov 15, 2018
shadows Allow setting system services as unavailable Nov 19, 2018
testapp Make enabled and other flags in the manifest visible in the Component… Nov 12, 2018
utils Clean up warnings and noise. Nov 15, 2018
.gitignore Ignore CTS dirs for now. Jun 9, 2017
.travis.yml Configure travis for API 27 Oct 26, 2017
CODE_OF_CONDUCT.md Update CODE_OF_CONDUCT.md Feb 26, 2017
LICENSE LICENCE file cleanup. Mar 29, 2017
README.md Update README.md Nov 10, 2018
WORKSPACE move workspace file Feb 6, 2018
build.gradle 4075 - update android gradle plugin to 3.2.1 Nov 5, 2018
gradle.properties Fix gradle build Oct 29, 2018
gradlew upgrade gradle to 4.1 Aug 24, 2017
gradlew.bat upgrade gradle to 4.1 Aug 24, 2017
resources.arsc Read binary resources using transliterated Android C++ code (currentl… Mar 23, 2018
settings.gradle -Create a new module for androidx fragment. Sep 27, 2018

README.md

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

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.1-SNAPSHOT"
}