• Home
Name Date Size #Lines LOC

..--

.devcontainer/04-Jul-2025-10383

.github/04-Jul-2025-774558

annotations/04-Jul-2025-2,8881,781

buildSrc/04-Jul-2025-1,080799

errorprone/04-Jul-2025-1,200980

gradle/04-Jul-2025-280209

images/04-Jul-2025-

integration_tests/04-Jul-2025-41,32231,850

junit/04-Jul-2025-812619

nativeruntime/04-Jul-2025-7,2954,760

pluginapi/04-Jul-2025-709333

plugins/maven-dependency-resolver/04-Jul-2025-1,013856

preinstrumented/04-Jul-2025-466382

processor/04-Jul-2025-5,5544,477

resources/04-Jul-2025-31,76120,666

robolectric/04-Jul-2025-137,684111,485

sandbox/04-Jul-2025-8,0486,262

scripts/04-Jul-2025-859645

shadowapi/04-Jul-2025-1,5711,122

shadows/04-Jul-2025-141,431104,296

simulator/src/main/java/org/robolectric/simulator/04-Jul-2025-920741

soong/04-Jul-2025-138104

testapp/04-Jul-2025-2,3621,785

utils/04-Jul-2025-4,8603,612

.gitignoreD04-Jul-2025552 6754

ARCHITECTURE.mdD04-Jul-202589 21

Android.bpD04-Jul-202511.2 KiB308285

CODE_OF_CONDUCT.mdD04-Jul-20253.2 KiB7556

LICENSED04-Jul-202512.6 KiB234192

METADATAD04-Jul-2025307 1615

MODULE_LICENSE_MITD04-Jul-20250

NOTICED04-Jul-20251.1 KiB2217

OWNERSD04-Jul-2025208 65

README.mdD04-Jul-20254.5 KiB9869

WORKSPACED04-Jul-202536 11

build.gradle.ktsD04-Jul-20257.2 KiB227189

gradle.propertiesD04-Jul-20251 KiB2619

gradlewD04-Jul-20258.6 KiB253105

gradlew.batD04-Jul-20252.9 KiB9573

harddiff.shD04-Jul-20251.2 KiB5540

settings.gradle.ktsD04-Jul-20251.4 KiB6358

README.md

1<a name="README">[<img src="https://rawgithub.com/robolectric/robolectric/master/images/robolectric-horizontal.png"/>](https://robolectric.org)</a>
2
3[![Build Status](https://github.com/robolectric/robolectric/actions/workflows/tests.yml/badge.svg)](https://github.com/robolectric/robolectric/actions?query=workflow%3Atests)
4[![GitHub release](https://img.shields.io/github/release/robolectric/robolectric.svg?maxAge=60)](https://github.com/robolectric/robolectric/releases)
5
6Robolectric 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 and flakiness of an emulator. Robolectric tests routinely run 10x faster than those on cold-started emulators.
7
8Robolectric supports running unit tests for *15* different versions of Android, ranging from Lollipop (API level 21) to V (API level 35).
9
10## Usage
11
12Here's an example of a simple test written using Robolectric:
13
14```java
15@RunWith(AndroidJUnit4.class)
16public class MyActivityTest {
17
18  @Test
19  public void clickingButton_shouldChangeResultsViewText() {
20    Activity activity = Robolectric.setupActivity(MyActivity.class);
21
22    Button button = (Button) activity.findViewById(R.id.press_me_button);
23    TextView results = (TextView) activity.findViewById(R.id.results_text_view);
24
25    button.performClick();
26    assertThat(results.getText().toString(), equalTo("Testing Android Rocks!"));
27  }
28}
29```
30
31For more information about how to install and use Robolectric on your project, extend its functionality, and join the community of contributors, please visit [robolectric.org](https://robolectric.org).
32
33## Install
34
35### Starting a New Project
36
37If you'd like to start a new project with Robolectric tests, you can refer to `deckard` (for either [Maven](https://github.com/robolectric/deckard-maven) or [Gradle](https://github.com/robolectric/deckard-gradle)) as a guide to setting up both Android and Robolectric on your machine.
38
39### `build.gradle`
40
41```groovy
42testImplementation "junit:junit:4.13.2"
43testImplementation "org.robolectric:robolectric:4.14.1"
44```
45
46## Building and Contributing
47
48Robolectric is built using Gradle. Both Android Studio and IntelliJ can import the top-level `build.gradle.kts` file and will automatically generate their project files from it.
49
50To get Robolectric up and running on your machine, check out
51[this guide](https://robolectric.org/building-robolectric/).
52
53To get a high-level overview of Robolectric's architecture, check out
54[robolectric.org](https://robolectric.org/architecture).
55
56## Development model
57
58Robolectric is actively developed in several locations. The primary location is
59this GitHub repository, which is considered the *source-of-truth* for
60Robolectric code. It is where contributions from the broader Android developer
61community occur. There is also an active development tree of Robolectric
62internally at Google, where contributions from first-party Android developers
63occur. By having a development tree of Robolectric internally at Google, it
64enables first-party Android developers to more efficiently make contributions
65to Robolectric. This tree is synced directly to the [`google`
66branch](https://github.com/robolectric/robolectric/tree/google) every
67time a change occurs using the [`Copybara`](https://github.com/google/copybara)
68code sync tool. Bidirectional merges of this branch and the
69[`master`](https://github.com/robolectric/robolectric/tree/master) branch occur
70regularly.
71
72Robolectric also has usage in the Android platform via the
73[external/robolectric](https://cs.android.com/android/platform/superproject/main/+/main:external/robolectric/)
74repo project. Contributions to this source tree are typically related to new
75SDK support and evolving platform APIs. Changes from this branch are upstreamed
76to the internal Robolectric tree at Google, which eventually propagate to the
77GitHub branches.
78
79Although complex, this distributed development model enables Android developers
80in different environments to use and contribute to Robolectric, while allowing
81changes to eventually make their way to public Robolectric releases.
82
83## Using Snapshots
84
85If 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 the `master` and may contain bugs.
86
87### `build.gradle`
88
89```groovy
90repositories {
91    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
92}
93
94dependencies {
95    testImplementation "org.robolectric:robolectric:4.15-SNAPSHOT"
96}
97```
98