Android Gradle Groovy App Template

March 28, 2017 ยท View on GitHub

License TravisCI Build Coveralls Code Coverage Twitter Follow

Gradle + Android Studio + Robolectric + Espresso + RoboSpock + JaCoCo

Technologies used:

Build Tools:

NameDescription
GradleGradle build system
Android Gradle Build ToolsOfficial Gradle Plugin
Android SDKOfficial SDK
Android SDK Build ToolsOfficial Build Tools
Android Studio orOfficial IDE
IntellijIntellij IDE

Android Libraries:

NameDescription
Android Support-v4Support Library API 4+
Android AppCompat-v7Support Library API 7+

Testing Frameworks:

NameDescription
EspressoInstrumentation Framework
RobolectricUnit Testing Framework

Reporting Plugins:

NameDescription
JaCoCoJaCoCo Test Coverage
CoverallsHosts test reports published from TravisCI

Continuous Integration:

NameDescription
TravisCIBuild Server(Builds, Tests, Publishes reports to Coveralls)

Publishing to Google Play:

NameDescription
Gradle-play-publisherPublishes your app to Google Play

Getting Started:

Android Studio or Intellij Support(Simple):

  • Import/Open this project with Android Studio/Intellij(click on build.gradle)

  • Instrumentation Tests:

    • Change the Build Variant Test Artifact to Instrumentation Tests
    • Right click an instrumentation test located in src/main/androidTest and click test
  • Unit Tests:

    • Change the Build Variant Test Artifact to Unit Tests
    • Right click a unit test located in src/main/test and click test

Building and Running

This project builds with Gradle and the Android Build tools.

Build the APK:

$ gradlew assembleDebug

Install the APK:

$ gradlew installDebug

Run the App:

$ gradlew runDebug

Testing

Running the Unit Tests:

The Junit tests run on the JVM, no need for emulators or real devices.

$ gradlew testDebug

Run a single unit test in the debug flavor:

$ gradlew testDebug --tests="*MainActivityTest*"

Running the Instrumentation Tests:

The Espresso instrumentation tests run on the device.

$ gradlew connectedDebugAndroidTest

Reports

Generate Lint Reports:

The Lint plugin generates reports based off the source code.

$ gradlew lintDebug

Generate Jacoco Test Coverage:

The Jacoco plugin generates coverage reports based off the unit tests.

$ gradlew jacocoDebugReport