Skip to content

Commit

Permalink
Move non-essential sections of the README to the wiki.
Browse files Browse the repository at this point in the history
  • Loading branch information
erd committed Jul 31, 2014
1 parent 2ac3d4c commit ccf0fa0
Showing 1 changed file with 2 additions and 57 deletions.
59 changes: 2 additions & 57 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ A Gradle plugin which enables Robolectric tests.

## Compatibility

Currently known to work with Gradle 1.11, Android Gradle Plugin 0.11.x, Android Studio 0.6.x, and IntelliJ IDEA 13.
Currently compatible with version 0.11.x of the android gradle plugin.

## Getting Started

Expand All @@ -28,13 +28,10 @@ apply plugin: 'robolectric'

Add test-only dependencies using the `androidTestCompile` configuration:
```groovy
androidTestCompile 'junit:junit:4.10'
androidTestCompile 'org.robolectric:robolectric:2.3.+'
androidTestCompile 'com.squareup:fest-android:1.0.+'
```

Write your tests in `src/test/java/`! You can also add per-build type and per-flavor tests by using
the same folder naming conventions (e.g., `src/testPaid/java/`, `src/testDebug/java/`).
Place your tests in `src/test/java` or `src/androidTest/java` You can also add per-build type and per-flavor tests by using the same folder naming conventions (e.g., `src/testPaid/java`, `src/testDebug/java`).

Run your tests by calling `gradle clean test`.

Expand Down Expand Up @@ -70,58 +67,6 @@ It bears repeating, though: if you see the dreaded `Stub!` exception:

...you will have to hand-edit your dependencies (in the IDE for IntelliJ, or hand-editing your IML file in Studio). See [deckard-gradle](https://github.com/robolectric/deckard-gradle) for details.

## Robolectric 2.2 or earlier

Version 2.3 of Robolectric will support this plugin out of the box ([see here](https://github.com/robolectric/robolectric/pull/744)).
Until then, you can use the following test runner:
```java
import org.junit.runners.model.InitializationError;
import org.robolectric.AndroidManifest;
import org.robolectric.RobolectricTestRunner;
import org.robolectric.annotation.Config;
import org.robolectric.res.Fs;

public class RobolectricGradleTestRunner extends RobolectricTestRunner {
public RobolectricGradleTestRunner(Class<?> testClass) throws InitializationError {
super(testClass);
}

@Override protected AndroidManifest getAppManifest(Config config) {
String manifestProperty = System.getProperty("android.manifest");
if (config.manifest().equals(Config.DEFAULT) && manifestProperty != null) {
String resProperty = System.getProperty("android.resources");
String assetsProperty = System.getProperty("android.assets");
return new AndroidManifest(Fs.fileFromPath(manifestProperty), Fs.fileFromPath(resProperty),
Fs.fileFromPath(assetsProperty));
}
return super.getAppManifest(config);
}
}
```

Just annotate your test classes with `@RunWith(RobolectricGradleTestRunner.class)` or subclass this
test runner if you have other customizations.

## Plugin Development

The `example/` dir contains a project which covers a few configurations for the plugin to work with.

1. Run `./gradlew install` in the root. This will build the plugin and install it into a local Maven
repository.
2. In the `example/` folder, run `../gradlew clean check` to build and run the unit tests.
3. Open `example/build/test-report/index.html` in the browser.

### Debugging

You can run the plugin in the debugger, but it takes some setup.

1. Execute this at the root of your project:
```
GRADLE_OPTS="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5006" ./gradlew test --no-daemon -Dorg.gradle.debug=true
```
2. Point a remote debugger to port 5006. In Intellij set up 'Remote' Debug configuration and set the port (actual port can be changed)
3. In IntelliJ, to break at breakpoints inside of our plugin or other gradle code you will need to put the appropriate JARs on your classpath, and then attach the source. It's a bit of a hack but it is possible in IntelliJ, anyway :).
## License

Copyright 2013 Square, Inc.
Expand Down

0 comments on commit ccf0fa0

Please sign in to comment.