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 ... |
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access