This sample android app demonstrates how to setup Robolectric to write/run tests and how to create a continuous integration/deployment setup in Wercker.
- Creating an Android Project in Android Studio
- Integrating Robolectric
- Writing Your First Test
- Running Robolectric Tests
- Continuous Delivery using Wercker
- Setting Environment-dependent Configurations
- Generating Signed APK in Wercker
Create a blank activity project in Android Studio with MainActivity. Android Studio uses a gradle-based build setup which also makes it easy to run Robolectric tests .
Add junit
and robolectric
as dependencies in app/build.gradle
dependencies {
...
compile 'junit:junit:4.12'
compile "org.robolectric:robolectric:3.0"
}
See the wiki page for a detailed version: Integrating Robolectric to Android App
Test files reside in app/src/test/
directory. For now, create a test file for MainActivity, MainActivityTest.
The file contains a sample test. To learn more about writing Robolectric tests, see: Robolectric Samples
You can run the tests via the terminal. Go to the root directory of the project and run:
./gradlew clean test
To build APK locally, run:
./gradlew clean build
The wercker.yml configuration takes care of running the tests and building the app once it it pushed to remote using Wercker. It uses a docker container to build/deploy applications.
You might want to use different variables or configurations based on the environment. The easiest way to achieve this is to create a Configuration.java.example file containing default configuration for release environment. While developing locally, copy this file:
cp Configuration.java.example Configuration.java
and change it to configuration required for local development. Configuration.java
should be added to .gitignore
to avoid accidentally committing the file. circle.yml
file contains the command to copy the example file and generate Configuration.java
before creating the release APK.
Check out our OneMDM Client for a configuration file (Config.java.example) with more examples.
Check out the wiki page to know how to generate a signed APK from wercker: Creating Signed APK in Wercker