Testing Your Changes
We saw the basics of testing in Android back in a previous chapter. However, that was just with some pre-defined tests created by Android Studio’s new-project wizard.
Presumably, your app will have more code that needs testing.
(if your app is purely the result of the new-project wizard templates, feel free to skip this chapter)
In this chapter, we will explore a bit more about how to write and run tests in Android, so that you can test your app code.
A Quick Recap
There are two broad categories of tests in Android: instrumented tests and unit tests.
Instrumented tests:
- Run in Android, on a device or emulator
- Have full access to the Android SDK, so you can test most of your app
- Run relatively slowly
Unit tests:
- Run outside of Android, directly on your development machine or CI server, in whatever operating system that is running (Windows, macOS, Linux)
- Have no access to the actual Android SDK, so your testing will tend to be focused on pure-Java/Kotlin code
- Run relatively quickly
Both categories of tests will look the same on the surface, in that both use JUnit4 and have similar structures (e.g., @Test
-annotated methods or functions).
Prev Table of Contents Next
This book is licensed under the Creative Commons Attribution-ShareAlike 4.0 International license.