Code Monkey home page Code Monkey logo

robolectric's Introduction

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(RobolectricGradleTestRunner.class)
@Config(constants = BuildConfig.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.

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:3.1"

Maven

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

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. You will need to have portions of the Android SDK available in your local Maven repo in order to build Robolectric.

Mavenize all required dependencies by running:

./scripts/install-dependencies.rb

Because Robolectric's shadows are compiled against the Android APIs that they target, you must build the shadows for all API levels before being able to run any of the tests. You can build all of Robolectric by running:

./scripts/install-robolectric.sh

After doing this once, you can build and test against the specific API level you care about:

mvn install -P android-18 (for example)

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.2-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.2-SNAPSHOT</version>
   <scope>test</scope>
</dependency>

robolectric's People

Contributors

erd avatar xian avatar jongerrish avatar jakewharton avatar jberkel avatar cessationoftime avatar tylerschultz avatar ngbravo avatar roman-mazur avatar mportuesisf avatar coreydowning avatar lexs avatar rjrjr avatar pforhan avatar seadowg avatar erichaugh avatar dnkoutso avatar adamcohenrose avatar msama avatar yuzhong-google avatar thorikawa avatar joemoore avatar rcdickerson avatar ry4n1m3 avatar avh4 avatar roberttaylor426 avatar blurpy avatar ecgreb avatar gesellix avatar palfrey avatar

Stargazers

Felipe Monteiro avatar

Watchers

Matías Iturburu avatar Hendrigo Cunha avatar Bruno Elia avatar M G Berrotaran avatar mrege avatar Sabrina Jucá Neri avatar Leandro Quintana avatar  avatar Dayvison Lemos avatar Luis Darío Simonassi avatar Matias Debard avatar Valmir Justo avatar Harold Sánchez Balaguera avatar Pedro Bogado avatar Roberto Bravo avatar William Witter da Silva avatar Walter Alini avatar Iram Garcia avatar Ignacio Ricci avatar Alejandro avatar Pablo Rodriguez Valenzuela avatar Reinaldo Oliveira Yamauti avatar Ivan Pasquini avatar  avatar Mariano Guelar avatar Fernando Cambarieri avatar Juan Marchese avatar  avatar Diego Ghersi avatar James Cloos avatar Daniel Goldberg avatar Miguel Antequera avatar Juan Manuel avatar Luciana Gatica avatar  avatar Mauricio Parra Casado avatar David De Freitas avatar Salvador Roibon avatar Francisco J. Capdevila avatar Juan Sanzone avatar Alejandro Cáceres Prado avatar  avatar Rafael Bernardo avatar André Justi avatar Pablo Peralta avatar Victoria Mesa Alcorta avatar jmrozanec avatar Isac de Souza Cajá avatar Fernando da Silva Rosa avatar Nicolas Pessolani avatar Cristhian Boujon avatar  avatar @_davidcolman avatar Angeles de la Torre avatar Claudio Bustamante A. avatar Mariano Della Vedova avatar Ignacio Alvarez avatar  avatar Damian Albanesi avatar Salah Rifai avatar Lucas J. Kolaric avatar Josue Hernandez avatar Nicolas Battelli avatar oscar osorio avatar  avatar  avatar  avatar Dana avatar  avatar Carlos David Rios Vertel avatar Juan Pablo de Blas avatar Fabricio avatar Sebastián Allende avatar Tomas Fontenla avatar  avatar Alejandro Sazo Rojas avatar Jorge Plaza avatar Bruno Ferreira avatar Gustavo Mena avatar Franco Martinez avatar Fernando avatar  avatar Abrahan A avatar Javier Scappini avatar Rafael de Aquino Cunha avatar Luciano Magro Mores avatar Mariano Hernández avatar Arel Sirin avatar German Bourdin avatar Guilherme Hayashi avatar  avatar Juan Pablo Ferrari avatar Alexandre Proença avatar Gastón André avatar Krikor Krikorian avatar Artiom Kolesnikov avatar Gus Rodriguez avatar Pablo Di Risio avatar Bruno Moura avatar Artur Giro Moreno avatar

Forkers

jsotuyod

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.