Fetching latest commit…
Cannot retrieve the latest commit at this time
|Failed to load latest commit information.|
|robolectric @ 63df9c2|
This is a sample project configured and setup to use Robolectric. This project shows how to configure your build file, how to layout your project, sample tests, etc. There are caveats: - This project was initially setup to use IntelliJ (Pivotal's Java IDE of choice), however Eclipse support is now included, so please let us know if you have any problems running under Eclipse. - Currently the library has some requirements on using the Google API's versions of the SDK. - Sometimes IntelliJ's module settings dialog re-adds the "code/gen" directory as a source in the main Android module, causing an error to appear; just manually remove it to fix. To install this sample app and run the tests: git clone git://github.com/pivotal/RobolectricSample.git cd RobolectricSample git submodule update --init android update project -p . ant clean test To install the sample app on the emulator: ant debug adb -e install [-r] <your-project-name>-debug.apk PROJECT LAYOUT The project moves the source (and test) directory into a plain old Java module (named the code module) so IntelliJ won't run the really slow dex step every time the project is built (every time you run tests). The code module has a compile dependency on android the sdk library, allowing you to write your classes as you normally would. If you are running in Eclipse you should not include the code/test folder as a source folder and follow the instructions in the Robolectric Quick Start guide instead of creating an Android test project. This document can be found at: http://pivotal.github.com/robolectric/quick-start.html The Android resources generated classes (R.class) is generated into the code module, so your code can refer to it. The main Android module depends on the code module, and performs the dex build step. The optional aidls module contains any service aidls for your project. The main module has a dependency to it, but code does not. Code generated from aidls is generated into the code module by the Android build task. ANT The project contains a build.xml configured for the layout of the project. The file extends the standard Android build.xml to support the layout of the project files. The build.xml file defines a test target. This sample project and build.xml file also has support for the aidls your application may define. Currently there are no samples demonstrating this, but we have successfully used this setup on projects that define aidls. WRITING TESTS If you're reading this, you probably know that the Android SDK jar is basically unusable outside of the Emulator or a device. All sdk methods throw RuntimeExceptions("STUB!"). Robolectric de-fangs the sdk jar by rewriting the contents of all the methods in the sdk at runtime. By default, the methods are rewritten to do nothing and return null. You may provide a shadow class to handle specific method calls. Robolectric provides many shadow objects, but it is not complete, or necessarily completely realistic. Most of what you'll need is there, but don't be surprised if you have to write a shadow for the functionality you're testing. Robolectric requires that tests classes are loaded with a custom test runner so that it has a chance to prepare for calls into the sdk. Tests can then be written as you normally would write them. Helper methods exist to provide access to the shadow objects backing the real Android objects (shadowOf()). Robolectric handles inflation of views, string resource lookups, etc. Only some view attributes (id, visibility, enabled, text, checked, and src) are currently parsed and applied to inflated views. GETTING STARTED For now we recommend that you start with this skeleton application and add your code to it. For buggy and wrong pointers on how to convert your existing project, see CONVERTING-EXISTING-APPS. CONTRIBUTING We welcome contributions. Please fork and submit pull requests!