Allows running Robolectric tests directly from the Android Studio.
This script works with com.android.tools.build:gradle:0.14.0 and Android Studio v0.9.1
Add robolectric to your project as described here:
https://github.com/robolectric/deckard-gradle.
Complete all steps before "IntelliJ / Android Studio Support".
- Place robolectric-iml.gradle near the build.gradle file.
- Apply it after android plugin
Setup your default JUnit configuration:
EditConfigurations ... -> Defaults -> JUnit
- Remove Make from Before launch section
- Add new Before launch entry, Run external tool
- Give it any name
- Program: ./gradlew
- Parameters: --daemon --offline testDebugClasses
- Working directory:
- Apply everything
Now you can run your robolectric tests from the IDE.
Q: Could we launch gradle task, not external tool?
A: Yes, but in this case gradle task is run simultaneously with the tests (for some strange reason), which can cause some race conditions.
Q: Could we use macros instead of hardcoded project path?
A: Yes, but for me it broke after first build.