Android & Kotlin Requires a pro subscription Pro

Android Test-Driven Development by Tutorials

A book that teaches you to write sustainable, testable apps, as well as to apply testing strategies to legacy projects via Espresso and UI tests, code coverage and refactoring. By Fernando Sproviero, Victoria Gonda & Lance Gleason.

Read for Free with the Pro subscription* * Includes this and all other books in our online library See all benefits
Buy Individually $59.99 $35.99* *Includes access to all of our online reading features.
Login to leave a rating/review
Download materials
Buy paperback—Amazon Comments
Save for later
Share

Who is this for?

This book is for the intermediate Android developers who already know the basics of Android and Kotlin development but want to learn Android Test-Driven Development.

Covered concepts

  • Getting Started with Testing
  • Test-Driven Development (TDD)
  • The Testing Pyramid
  • Unit Tests
  • Integration Tests
  • Architecting for Testing
  • TDD on Legacy Projects
Learn Test-Driven Development on Android!

Writing apps is hard. Writing testable apps is even harder, but it doesn’t have to be. Reading and understanding all the official Google documentation on testing can be time-consuming — and confusing.

In this book, you’ll learn about Android test-driven development the quick and easy...

more

Before You Begin

This section tells you a few things you need to know before you get started, such as what you’ll need for hardware and software, where to find the project files for this book, and more.

Section I: Introduction to Test-Driven Development

This section introduces you to Android test-driven development (TDD). If testing or TDD are new concepts to you, we recommend starting here. You’ll learn everything from what a test is, why you should test, what you should test, and what you should not test.

You’ll then get your feet wet by writing your first Kotlin test, independent of the Android framework, with the principles of TDD. This section lays the foundation for TDD.

1
Hide description
If you're new to testing and want an overview of what this book covers, start with Chapter 1 for a gentle introduction to testing.
2
Hide description
Do you know why you should test or what to test? In this chapter, "What is a Test?", you'll learn both of these and also dive into code coverage.
3
Hide description
Now that you know what a test is, start writing your first tests! Not only will you start writing tests, but you'll also do so in a test-driven development way.

Section II: Testing on a New Project

This section dives deep into the art of TDD. You’ll learn about the different types of tests that make up the testing pyramid and how to implement all of these different kinds of tests into an app.

You’ll learn how to write unit tests, integration tests, and using UI testing to verify your app works as expected end to end.

4
Hide description
If you're wondering how UI tests, integration tests and unit tests all fit into one application, learn about the testing pyramid and how you can structure various types of tests for your app.
5
Hide description
Get your drink ready as you explore a cocktail app and write your unit tests in Android practicing test-driven development.
6
Hide description
The architecture of your project can make or break your testing experience. Learn the pros and cons of each architecture and how they affect your tests.
Hide description
Level up your testing knowledge leveraging Mockito as you learn the basics of how to use mocks and spies in your tests.
Hide description
Often, you'll need to test the interaction between objects in your application. In this chapter, you'll practice writing integration tests by working on a Wishlist app.
Get started learning how to test the persistence layer in your app. In this chapter, you'll learn how to handle statefulness in your tests and strategies for creating randomized test data.
Hide description
While HTTP requests can be unpredictable, your tests don't have to be. In this chapter, learn how to write predictable network tests working on the Punchline app. Learn some random jokes on the way as well!
Hide description
UI tests allow you to test your app end-to-end without having to manually click-test your app. Learn the fundamentals of UI tests using the Espresso library.

Section III: TDD on Legacy Projects

Now that you have an understanding of TDD and have different tools at your disposal, you’ll learn how to apply these techniques to projects that weren’t created using TDD and do not have sufficient test coverage. You’ll work through Furry Coding Companion Finder on your way to becoming a TDD guru.

Hide description
Automated tests can help catch bugs in all applications, including legacy applications. Learn how to work around technical debt and apply testing techniques.
Get started with the Coding Companion Finder app as you work through a legacy application and write UI tests using Espresso.
Hide description
Refactoring a legacy application doesn't have to be scary once you have some tests for it. Learn how to take small steps and move slowly as you keep your test suite green as you make changes to your app.
Hide description
Your tests are code too. In this chapter, you'll learn how to refactor both your app code and test code to make your tests reliable and maintainable.
Learn multiple ways to handle test data in your Android tests by learning by tutorials. In this chapter, you'll explore a variety of ways of using test data in your tests.
Explore what it means to have continuous integration for your tests and the tools you can use to achieve it. You'll learn the pros and cons of different CI strategies in this chapter.
Set boundaries in your test and use strategies to help to interact with other libraries and parts of the Android framework.

Appendix

Learn about other techniques that can complement your TDD process to make your team more collaborative and therefore effective.