Chapter    2

Android Unit Testing

Before Android Studio incorporated JUnit4, Google’s implementation was an odd mix of standard and Android-specific unit tests. The current version of JUnit4 is a much more vanilla implementation of the JUnit standard (see http://junit.org for more information or https://github.com/junit-team/junit for the source code). The current recommended version of JUnit we’re loading in the build.gradle file is 4.12

Android Assertions

In our Hello, World example we used the assertEquals assertion, but there are other assertions in JUnit 4.12 that we can use (see Table 2-1).

Table 2-1. Assertions

Assertion

Description

assertEquals

Test that two values are the same

assertTrue

Test Boolean condition is true

assertFalse ...

Get Agile Android now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.