• Home
Name Date Size #Lines LOC

..--

.github/06-Sep-2024-746544

annotations/06-Sep-2024-2,6931,677

buildSrc/06-Sep-2024-713583

errorprone/06-Sep-2024-1,209994

gradle/06-Sep-2024-259191

images/06-Sep-2024-

integration_tests/06-Sep-2024-34,83426,493

junit/06-Sep-2024-547419

nativeruntime/06-Sep-2024-7,0544,587

pluginapi/06-Sep-2024-712321

plugins/maven-dependency-resolver/06-Sep-2024-1,019866

preinstrumented/06-Sep-2024-383311

processor/06-Sep-2024-5,4334,370

resources/06-Sep-2024-31,11720,027

robolectric/06-Sep-2024-129,849104,906

sandbox/06-Sep-2024-8,0976,277

scripts/06-Sep-2024-850638

shadowapi/06-Sep-2024-1,5081,058

shadows/06-Sep-2024-133,00197,679

soong/06-Sep-2024-135101

testapp/06-Sep-2024-1,8321,558

utils/06-Sep-2024-5,6164,125

.gitignoreD06-Sep-2024534 6452

ARCHITECTURE.mdD06-Sep-202412.2 KiB214175

Android.bpD06-Sep-202410.9 KiB296274

CODE_OF_CONDUCT.mdD06-Sep-20243.2 KiB7556

LICENSED06-Sep-202412.6 KiB234192

METADATAD06-Sep-2024307 1615

MODULE_LICENSE_MITD06-Sep-20240

NOTICED06-Sep-20241.1 KiB2217

OWNERSD06-Sep-2024100 65

README.mdD06-Sep-20243.6 KiB9357

WORKSPACED06-Sep-202436 11

build.gradleD06-Sep-20247.4 KiB202180

dependencies.gradleD06-Sep-2024448 109

gradle.propertiesD06-Sep-202490 43

gradlewD06-Sep-20248.5 KiB250104

gradlew.batD06-Sep-20242.8 KiB9371

harddiff.shD06-Sep-20241.2 KiB5540

settings.gradleD06-Sep-20241.4 KiB4644

README.md

1<a name="README">[<img src="https://rawgithub.com/robolectric/robolectric/master/images/robolectric-horizontal.png"/>](http://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 *14* different versions of Android, ranging from Lollipop (API level 21) to U (API level 34).
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 [http://robolectric.org](http://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](http://github.com/robolectric/deckard-maven) or [gradle](http://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.11.1"
44```
45
46## Building And Contributing
47
48Robolectric 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.
49
50To get a high-level overview of Robolectric's architecture, check out
51[ARCHITECTURE.md](ARCHITECTURE.md).
52
53### Prerequisites
54
55See [Building Robolectric](http://robolectric.org/building-robolectric/) for more details about setting up a build environment for Robolectric.
56
57### Building
58
59Robolectric 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:
60
61    ./gradlew clean assemble testClasses --parallel
62
63### Testing
64
65Run tests for all API levels:
66
67> The fully tests could consume more than 16G memory(total of physical and virtual memory).
68
69    ./gradlew test --parallel
70
71Run tests for part of supported API levels, e.g. run tests for API level 26, 27, 28:
72
73    ./gradlew test --parallel -Drobolectric.enabledSdks=26,27,28
74
75Run compatibility test suites on opening Emulator:
76
77    ./gradlew connectedCheck
78
79### Using Snapshots
80
81If 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.
82
83#### build.gradle:
84
85```groovy
86repositories {
87    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
88}
89dependencies {
90    testImplementation "org.robolectric:robolectric:4.12-SNAPSHOT"
91}
92```
93