Testing

Some useful material for unit testing on Android:

    • Test classes (link)
    • Getting context (link)

Samples:

    • android-alltest-gradle-sample (link)

Tutorials:

    • Android Studio unit testing (link)

Unit Testing

Robolectric

Robolectric is a unit testing framework for Android. The tests run in JVM so there is no need to instantiate an Android emulator to execute them. This makes running them pretty fast. It still provides context emulation as well as many shadow classes so mocking is usually not needed.

    • Robolectric (link)
    • Roboelectric Tutorial (link), Vogella
    • How to get a context (link)

Mockito

Mockito is a mock/stub library. It can be used with Robolectric but is not necessary.

UI Testing

Selendroid

Selendroid (link), Selenium for Android

Robotium

Robotium is a set of tools/libraries for UI testing. The principle here is black-box testing of the whole app. These tests require an Android running, meaning that they execute either on a real device or in an emulator. However, the execution is pretty fast even if the tests are being modified because the app does not have to be deployed.

    • Robotium (link)
    • Robotium Tutorial, Vogella (link)
    • Robotium in Android Studio (link)
    • Set up Gradle/Android Studio (link)
    • Robotium with Android Studio (link), Stack Overflow
    • Testing activity in Android Studio (link)
    • Useful snippets (link)
    • ActivityInstrumentationTestCase2 (link)
    • ActivityTestRule (link)
    • Using Robotium to test Android Spinners (link)

Espresso

Espresso is Google's UI testing framework.

    • Android test kit (link)
    • Wiki (link)
    • Getting Started (link), disable animations
    • Using JUnit 4 (link)
    • Testing UI for a single app (link)
    • Android testing presentation (link)
    • How to use Espresso 2.0 (link)
    • Adventures in Espresso (link)

Spoon

Testing on multiple devices - link

Behaviour-Driven Development (BDD)

BDD is a design philosophy. It is an evolution of Test-Driven Development (TDD) and acceptance testing, and merges the two concepts together.

JBehave

    • JBehave (link), getting started (link)
    • Behavior-Driven Development (BDD) with JBehave, Gradle, and Jenkins (link)

Calabash

    • Calabash - Automated acceptance testing for mobile apps (link)
    • A better way to test Android applications using Calabash (link)

Matchers

Hamcrest matchers contain lots of useful matchers for assertions and comparison of elements during tests. Useful for both unit and UI tests.

    • Discovering Espresso for Android (link)