• Home
Name Date Size #Lines LOC

..--

annotations/03-May-2024-839527

images/03-May-2024-

junit/03-May-2024-380300

processor/03-May-2024-4,3993,455

resources/03-May-2024-30,40119,513

robolectric/03-May-2024-71,38457,122

sandbox/03-May-2024-6,9935,380

shadowapi/03-May-2024-1,195855

shadows/03-May-2024-76,27255,627

soong/03-May-2024-135101

src/main/resources/META-INF/services/03-May-2024-66

utils/03-May-2024-2,5941,812

.gitignoreD03-May-2024318 4736

Android.bpD03-May-20248 KiB244222

Android.mkD03-May-2024646 2214

CODE_OF_CONDUCT.mdD03-May-20243.2 KiB7556

LICENSED03-May-20241.1 KiB2217

METADATAD03-May-202439 43

OWNERSD03-May-2024217 1211

README.mdD03-May-20243 KiB7245

gen_test_config.mkD03-May-20241.4 KiB2511

java-timeoutD03-May-20243.4 KiB9542

list_failed.shD03-May-2024737 2915

report-internal.mkD03-May-20242.5 KiB6242

robotest-internal.mkD03-May-20244.4 KiB10070

robotest.shD03-May-20244.8 KiB150105

run_robolectric_module_tests.mkD03-May-20246.7 KiB10372

run_robotests.mkD03-May-202410.5 KiB229125

wrapper.shD03-May-20242.5 KiB7727

wrapper_test.shD03-May-20243.3 KiB173149

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://travis-ci.org/robolectric/robolectric.svg?branch=master)](https://travis-ci.org/robolectric/robolectric)
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 of an emulator.
7
8## Usage
9
10Here's an example of a simple test written using Robolectric:
11
12```java
13@RunWith(RobolectricTestRunner.class)
14public class MyActivityTest {
15
16  @Test
17  public void clickingButton_shouldChangeResultsViewText() throws Exception {
18    Activity activity = Robolectric.setupActivity(MyActivity.class);
19
20    Button button = (Button) activity.findViewById(R.id.press_me_button);
21    TextView results = (TextView) activity.findViewById(R.id.results_text_view);
22
23    button.performClick();
24    assertThat(results.getText().toString(), equalTo("Testing Android Rocks!"));
25  }
26}
27```
28
29For 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).
30
31## Install
32
33### Starting a New Project
34
35If 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.
36
37#### build.gradle:
38
39```groovy
40testImplementation "org.robolectric:robolectric:4.1"
41```
42
43## Building And Contributing
44
45Robolectric 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.
46
47You 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:
48
49    ./scripts/install-dependencies.rb
50
51*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.
52
53Robolectric 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:
54
55    ./gradlew clean assemble install compileTest
56
57### Using Snapshots
58
59If 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.
60
61#### build.gradle:
62
63```groovy
64repositories {
65    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
66}
67
68dependencies {
69    testImplementation "org.robolectric:robolectric:4.2-SNAPSHOT"
70}
71```
72