Fix performance issues caused by 8d15a25dcbb23

The earlier commit would maintain a static list of styles, and every time
a style resource was added to a theme, it would stay there until the end
of time (or termination of JVM). When executing thousands of tests, this
would lead to massive slowdown of test execution - over 2x increase in
our company's case.

Now, the duplicate styles are removed and the new one is added, which keeps
the list short and performance reasonable.

Change-Id: Ib7ed9321c31938577c78aab52a1d8380bf1be4e6
3 files changed
tree: 56cff4cc7ce9a9cfd017cec283ddefd5c5e5d2bb
  1. images/
  2. robolectric/
  3. robolectric-annotations/
  4. robolectric-processor/
  5. robolectric-resources/
  6. robolectric-shadows/
  7. robolectric-utils/
  8. scripts/
  9. .gitignore
  10. .travis.yml
  11. CONTRIBUTING.md
  12. LICENSE.txt
  13. pom.xml
  14. README.md
README.md

Build Status

Robolectric is a testing framework that de-fangs the Android SDK so you can test-drive the development of your Android app.

Usage

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 pressMeButton = (Button) activity.findViewById(R.id.press_me_button);
    TextView results = (TextView) activity.findViewById(R.id.results_text_view);

    pressMeButton.performClick();
    String resultsText = results.getText().toString();
    assertThat(resultsText, 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.

Install

Starting a new project

If you'd like to start a new project with Robolectric you can use deckard (for either maven or gradle). These project will guide you through setting up both Android and Robolectric on your machine.

Gradle

testCompile "org.robolectric:robolectric:2.4"

Maven

<dependency>
   <groupId>org.robolectric</groupId>
   <artifactId>robolectric</artifactId>
   <version>2.4</version>
   <scope>test</scope>
</dependency>

Robolectric requires the Google APIs for Android (specifically, the maps JAR) and Android support-v4 library. To download this onto your development machine use the Android SDK tools and then run the following to install them to your local Maven repository (you will need to have the ‘Android Support Repository’ installed):

mvn install:install-file -DgroupId=com.google.android.maps \
  -DartifactId=maps \
  -Dversion=18_r3 \
  -Dpackaging=jar \
  -Dfile="$ANDROID_HOME/add-ons/addon-google_apis-google-18/libs/maps.jar"

mvn install:install-file -DgroupId=com.android.support \
  -DartifactId=support-v4 \
  -Dversion=19.0.1 \
  -Dpackaging=jar \
  -Dfile="$ANDROID_HOME/extras/android/m2repository/com/android/support/support-v4/19.0.1/support-v4-19.0.1.jar"

You will need to either replace or have ANDROID_HOME set to your local Android SDK for Maven to be able to install the jar.

Building And Contributing

Robolectric is built using Maven. Both Eclipse (with the M2Eclipse plug-in) and IntelliJ can import the pom.xml file and will automatically generate their project files from it.

Guides on to extending Robolectric can be found here and the contributor guidlines can be found here.

Using SNAPSHOTS

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.

Gradle

repositories {
    maven { url "https://oss.sonatype.org/content/repositories/snapshots" }
}

dependencies {
    testCompile "org.robolectric:robolectric:3.0-SNAPSHOT"
}

Maven

<repository>
  <id>sonatype-snapshpots</id>
  <url>https://oss.sonatype.org/content/repositories/snapshots</url>
</repository>

<dependency>
   <groupId>org.robolectric</groupId>
   <artifactId>robolectric</artifactId>
   <version>3.0-SNAPSHOT</version>
   <scope>test</scope>
</dependency>