commit | 2045ab69820a69180596e6eaddc5e2b27bded0e1 | [log] [tgz] |
---|---|---|
author | christianw <christianw@google.com> | Fri Dec 14 17:35:28 2018 -0800 |
committer | Copybara Robolectric Bot <copybara-robolectric@google.com> | Fri Dec 14 17:35:57 2018 -0800 |
tree | 7044ee494d7ffd7482e69d3657215916aeebfadf | |
parent | 738309a371f7f76531d547a20002b0caa51500e2 [diff] |
Cloned from CL 225628948 by 'g4 patch'. Original change by copybara-piper@copybara-piper:copybara_Standalone-050BE78872E38479E12CA3B1DC1BA555_0:17938:citc on 2018/12/14 17:25:45. Resolve AARs like the android plugins do (kind of). (PR#4279) No longer need `scripts/install-dependencies.rb` or `mvn`. You'll want to do this locally wherever that script as been run: ```sh ( cd ~/.m2/repository && rm -rf androidx \ && rm -rf com/android && rm -rf com/google/android ) ``` Pull Request: https://github.com/robolectric/robolectric/pull/4279 Commits: ---- f1572a02 - Christian Williams <christianw@google.com> - 2018-12-14T17:27:35-08:00 Fix imports. ---- 30f5aad0 - Christian Williams <christianw@google.com> - 2018-12-14T17:21:12-08:00 Remove another mavenLocal() repo. ---- 3541e50f - Christian Williams <christianw@google.com> - 2018-12-14T16:59:27-08:00 Workaround for IntelliJ bug with identical library names. ---- d53cc24e - Christian Williams <christianw@google.com> - 2018-12-09T23:31:01-08:00 compileOnly and testCompileOnly should be distinct or they screw up aar resolution. ---- 8d2cc3c8 - Christian Williams <christianw@google.com> - 2018-12-09T22:54:25-08:00 Fix transform scope. ---- e671a451 - Christian Williams <christianw@google.com> - 2018-12-09T21:43:11-08:00 Kill some log noise. ---- 9174e18f - Christian Williams <christianw@google.com> - 2018-12-09T21:40:20-08:00 Fixes. Refer to stubs jar explicitly from integration test. Explicitly call prefetchSdks for projects in the build that don't have a robolectric-deps.properties injected. ---- 10c90852 - Christian Williams <christianw@google.com> - 2018-12-09T21:28:25-08:00 Resolve AARs like the android plugins do (kind of). PiperOrigin-RevId: 225629873
Robolectric 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.
Here's an example of a simple test written using Robolectric:
@RunWith(RobolectricTestRunner.class) public class MyActivityTest { @Test public void clickingButton_shouldChangeResultsViewText() throws Exception { Activity activity = Robolectric.setupActivity(MyActivity.class); Button button = (Button) activity.findViewById(R.id.press_me_button); TextView results = (TextView) activity.findViewById(R.id.results_text_view); button.performClick(); assertThat(results.getText().toString(), equalTo("Testing Android Rocks!")); } }
For 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.
If you'd like to start a new project with Robolectric tests you can refer to deckard
(for either maven or gradle) as a guide to setting up both Android and Robolectric on your machine.
testImplementation "org.robolectric:robolectric:4.1"
Robolectric 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.
You 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:
./scripts/install-dependencies.rb
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.
Robolectric 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:
./gradlew clean assemble install compileTest
If 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.
repositories { maven { url "https://oss.sonatype.org/content/repositories/snapshots" } } dependencies { testImplementation "org.robolectric:robolectric:4.2-SNAPSHOT" }