Showing posts with label intellij. Show all posts
Showing posts with label intellij. Show all posts

Sunday, May 17, 2015

How to test Android with Gradle(Robolectric + EasyMock/PowerMock + JaCoCo + TravisCI)

How to test Android with Gradle + Android Studio + Robolectric + Mockito + EasyMock/PowerMock + JaCoCo + TravisCI

Here is my Github example:
https://github.com/jaredsburrows/AndroidGradleTemplate

AndroidGradleTemplate Status Coverage Status

Gradle + Android Studio + Robolectric + Mockito + EasyMock/PowerMock + JaCoCo

Technologies used:

Works with the following Configurations:
  • Multiple Modules
  • Multiple Flavors
  • Android Libraries

Getting Started:

Android Studio or Intellij Support(Simple):

  1. Import/Open this project with Android Studio/Intellij(click on build.gradle)
  2. Change the Build Variant Test Artifact to Unit Tests instead of Instrumentation Tests

Comand Line(Advanced):

Clone with Git:
  • git clone https://github.com/jaredsburrows/AndroidGradleTemplate.git
  • cd AndroidGradleTemplate
Installing/Running with Gradle:
  • Install the debug flavor on your Android Device:
    • gradlew installDebug
  • Install and Run the debug flavor on your Android Device:
    • gradlew runDebug
Testing with Gradle:
  • Run all tests in all flavors:
    • gradlew test
  • Run single test in all flavors:
    • gradlew test --tests="*MainActivityTest*"
  • Run all the debug flavor tests:
    • gradlew testDebug
  • Run single test in the debug flavor:
    • gradlew testDebug --tests="*MainActivityTest*"
  • Run single test in the debug flavor with Jacoco test reports:
    • gradlew testDebug --tests="*MainActivityTest*" jacocoTestReport

License

Copyright (C) 2015 AndroidGradleTemplate by Jared Burrows

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.