|
Name |
|
Date |
Size |
#Lines |
LOC |
| .. | | - | - |
| .github/ | | 03-May-2024 | - | 540 | 406 |
| annotations/ | | 03-May-2024 | - | 1,261 | 719 |
| buildSrc/ | | 03-May-2024 | - | 1,061 | 872 |
| errorprone/ | | 03-May-2024 | - | 1,213 | 998 |
| gradle/ | | 03-May-2024 | - | 250 | 186 |
| images/ | | 03-May-2024 | - | | |
| integration_tests/ | | 03-May-2024 | - | 33,744 | 25,679 |
| junit/ | | 03-May-2024 | - | 531 | 405 |
| nativeruntime/ | | 03-May-2024 | - | 6,489 | 4,155 |
| pluginapi/ | | 03-May-2024 | - | 712 | 321 |
| plugins/maven-dependency-resolver/ | | 03-May-2024 | - | 1,019 | 866 |
| preinstrumented/ | | 03-May-2024 | - | 437 | 357 |
| processor/ | | 03-May-2024 | - | 4,729 | 3,764 |
| resources/ | | 03-May-2024 | - | 30,924 | 19,890 |
| robolectric/ | | 03-May-2024 | - | 122,458 | 98,941 |
| sandbox/ | | 03-May-2024 | - | 8,414 | 6,457 |
| scripts/ | | 03-May-2024 | - | 851 | 639 |
| shadowapi/ | | 03-May-2024 | - | 1,331 | 931 |
| shadows/ | | 03-May-2024 | - | 131,414 | 96,817 |
| testapp/ | | 03-May-2024 | - | 1,800 | 1,529 |
| utils/ | | 03-May-2024 | - | 5,477 | 4,016 |
| .gitignore | D | 03-May-2024 | 534 | 64 | 52 |
| .gitmodules | D | 03-May-2024 | 0 | | |
| Android.bp | D | 03-May-2024 | 9.1 KiB | 266 | 243 |
| CODE_OF_CONDUCT.md | D | 03-May-2024 | 3.2 KiB | 75 | 56 |
| LICENSE | D | 03-May-2024 | 12.6 KiB | 234 | 192 |
| METADATA | D | 03-May-2024 | 307 | 16 | 15 |
| MODULE_LICENSE_MIT | D | 03-May-2024 | 0 | | |
| NOTICE | D | 03-May-2024 | 1.1 KiB | 22 | 17 |
| OWNERS | D | 03-May-2024 | 100 | 6 | 5 |
| README.md | D | 03-May-2024 | 4.2 KiB | 96 | 59 |
| WORKSPACE | D | 03-May-2024 | 36 | 1 | 1 |
| build.gradle | D | 03-May-2024 | 6.8 KiB | 192 | 169 |
| dependencies.gradle | D | 03-May-2024 | 511 | 12 | 10 |
| gradle.properties | D | 03-May-2024 | 90 | 4 | 3 |
| gradlew | D | 03-May-2024 | 8 KiB | 241 | 102 |
| gradlew.bat | D | 03-May-2024 | 2.8 KiB | 92 | 70 |
| settings.gradle | D | 03-May-2024 | 1.4 KiB | 45 | 43 |
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