Chapter 14. Testing

Developers write code. Often they write a lot of code. The web of dependencies between objects and other services is often complex and not easily discernible; objects depend on other objects to work property. Making a change in even relatively simple codebases in one place can cause a bug or a crash in another part of the codebase. The house of cards that is your app can come quickly crashing down.

Where does testing fit into all this? Testing is a way to provide developers with a level of confidence that the changes being made are not unknowingly affecting other parts of the application. Ideally, these tests would be automated and deterministic so as not to be subject to the unpredictable whims of humanity, in which error and poor judgment often present themselves. Fortunately, most modern platforms have testing built in. Both Android and iOS have full-featured and incredibly powerful testing tools that can be used to assist in developing code. Let’s see how these tools work.

Tasks

In this chapter, you’ll learn to:

  1. Set up and run unit tests.

  2. Set up and run integration tests.

Android

AOSP defines and differentiates a few different types of tests:

Unit tests

These are highly focused tests that run on a single class, usually a single method in that class. If a unit test fails, you should know exactly where in your code the issue is. They have low fidelity since in the real world, your app involves much more than the execution of one method or class. ...

Get Native Mobile Development 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.