Chapter 3. Application Testing

“Test early and often” is a common cry among advocates of testing, as is the all-important question, “If you don’t have a test, how do you know your code works?”

There are many types of testing. Unit testing checks out individual components (“units” such as methods) in isolation (not hitting the network or the database), whereas integration testing tests the entire system, or at least large swaths of it. JUnit and TestNG are the leading unit testing frameworks for Java. Mock objects are used where interaction with other components is required; there are several good mocking frameworks for Java. Android provides a number of specific testing techniques, many of which are discussed in this chapter.

In the broader scheme of things, software verification tools can be categorized as static or dynamic. JUnit is one example of a widely used method of dynamic testing, as is integration testing. Static code analysis works by examining the code rather than running it. Two well-known static analysis tools are FindBugs and PMD, which are covered in my book and my video series on testing. This site also has a bibliography of testing books/papers and a list of Java-specific testing tools. Android has its own static analysis tool, Android Lint, covered in Recipe 3.12.

Android apps can be run on a vast array of devices, including small phones, mid-sized tablets, large phones, large tablets, and (as of ChromeOS Release 53) most Chromebooks. They also run on many proprietary ...

Get Android Cookbook, 2nd Edition 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.