• Home
Name Date Size #Lines LOC

..--

.github/03-May-2024-540406

annotations/03-May-2024-1,261719

buildSrc/03-May-2024-1,061872

errorprone/03-May-2024-1,213998

gradle/03-May-2024-250186

images/03-May-2024-

integration_tests/03-May-2024-33,74425,679

junit/03-May-2024-531405

nativeruntime/03-May-2024-6,4894,155

pluginapi/03-May-2024-712321

plugins/maven-dependency-resolver/03-May-2024-1,019866

preinstrumented/03-May-2024-437357

processor/03-May-2024-4,7293,764

resources/03-May-2024-30,92419,890

robolectric/03-May-2024-122,45898,941

sandbox/03-May-2024-8,4146,457

scripts/03-May-2024-851639

shadowapi/03-May-2024-1,331931

shadows/03-May-2024-131,41496,817

testapp/03-May-2024-1,8001,529

utils/03-May-2024-5,4774,016

.gitignoreD03-May-2024534 6452

.gitmodulesD03-May-20240

Android.bpD03-May-20249.1 KiB266243

CODE_OF_CONDUCT.mdD03-May-20243.2 KiB7556

LICENSED03-May-202412.6 KiB234192

METADATAD03-May-2024307 1615

MODULE_LICENSE_MITD03-May-20240

NOTICED03-May-20241.1 KiB2217

OWNERSD03-May-2024100 65

README.mdD03-May-20244.2 KiB9659

WORKSPACED03-May-202436 11

build.gradleD03-May-20246.8 KiB192169

dependencies.gradleD03-May-2024511 1210

gradle.propertiesD03-May-202490 43

gradlewD03-May-20248 KiB241102

gradlew.batD03-May-20242.8 KiB9270

settings.gradleD03-May-20241.4 KiB4543

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 *17* different versions of Android, ranging from Jelly Bean (API level 16) to TIRAMISU (API level 33).
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.10.3"
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
50### Prerequisites
51
52Those software configurations are recommended and tested.
53
54- JDK 11. Gradle JVM should be set to Java 11.
55  - For command line, make sure the environment variable `JAVA_HOME` is correctly point to JDK11, or set the build environment by [Gradle CLI option](https://docs.gradle.org/current/userguide/command_line_interface.html#sec:environment_options) `-Dorg.gradle.java.home="YourJdkHomePath"` or by [Gradle Properties](https://docs.gradle.org/current/userguide/build_environment.html#sec:gradle_configuration_properties) `org.gradle.java.home=YourJdkHomePath`.
56  - For both IntelliJ and Android Studio, see _Settings/Preferences | Build, Execution, Deployment | Build Tools | Gradle_.
57
58See [Building Robolectric](http://robolectric.org/building-robolectric/) for more details about setting up a build environment for Robolectric.
59
60### Building
61
62Robolectric 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:
63
64    ./gradlew clean assemble testClasses --parallel
65
66### Testing
67
68Run tests for all API levels:
69
70> The fully tests could consume more than 16G memory(total of physical and virtual memory).
71
72    ./gradlew test --parallel
73
74Run tests for part of supported API levels, e.g. run tests for API level 26, 27, 28:
75
76    ./gradlew test --parallel -Drobolectric.enabledSdks=26,27,28
77
78Run compatibility test suites on opening Emulator:
79
80    ./gradlew connectedCheck
81
82### Using Snapshots
83
84If 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.
85
86#### build.gradle:
87
88```groovy
89repositories {
90    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
91}
92dependencies {
93    testImplementation "org.robolectric:robolectric:4.11-SNAPSHOT"
94}
95```
96