Learn Test Driven Development on Android!

It is difficult to write applications. Writing testable applications is harder, but it doesn’t have to be. Reading and understanding all the official Google documentation about testing can be time-consuming and confusing.

In this book, you will learn about Android test-driven development quickly and easily by learning interesting and easy-to-read tutorials. Learn to write sustainable, testable applications, and apply testing strategies to legacy projects through Espresso and UI testing, code coverage, and refactoring.

This book is suitable for intermediate Android developers who already know the basics of Android and Kotlin development but want to learn Android test-driven development.

Topics covered in this book

  • start testing: Understand the core concepts involved in testing, including what is a test, why it should be tested, what should be tested, and what should not be tested.

  • Test Driven Development (TDD): Learn about the red-green reconstruction steps and how to apply them.

  • Test pyramid: Learn about the different types of tests and how to organize them.

  • unit test: Learn how to use JUnit and Mockito to start writing unit tests with TDD.

  • Integration Testing: In today’s complex application world, it is necessary to write tests using different subsystems. Learn how to use different subsystems for testing, including persistence and network layers.

  • Test architecture: Explore how to build an application for testing and its importance.

  • TDD for legacy projects: Take your TDD to a new level by learning how to apply TDD to existing legacy projects.

Before you start

This section will tell you some things you need to know before you start, such as what hardware and software you need, where you can find the project files for this book, and so on.

Part 1: Introduction to Test Driven Development

This section introduces you to Android Test Driven Development (TDD). If testing or TDD is a new concept to you, we recommend starting here. You will learn everything about what a test is, why it should be tested, what should be tested, and what should not be tested.

Then, you will write your first Kotlin test independent of the Android framework based on the principles of TDD. This section lays the foundation for TDD.

If you are new to testing and want to understand what this book covers, please start with Chapter 1 to give a brief introduction to testing.

Do you know why or what to test? In the “What is a test?” chapter, you will learn both of these and gain insight into code coverage.

Now that you know what a test is, start writing your first test! Not only will you start writing tests, but you will also write them in a test-driven development style.

Part 2: Testing the new project

This section delves into the art of TDD. You will learn about the different types of tests that make up the testing pyramid and how to implement all these different types of tests into your application.

You will learn how to write unit tests, integration tests, and use UI tests to verify that your application runs end-to-end as expected.

If you want to know how UI testing, integration testing, and unit testing all fit into an application, learn about the testing pyramid and how to build various types of tests for your application.

Prepare your drink while exploring the cocktail application and practicing test-driven development in Android and writing unit tests.

The structure of the project can make or break your testing experience. Understand the advantages and disadvantages of each architecture and how they affect your testing.

Use Mockito to improve your testing knowledge as you learn how to use the basics of simulation and spying in your testing.

Usually, you need to test the interaction between objects in your application. In this chapter, you will practice writing integration tests by using the Wishlist application.

Start learning how to test the persistence layer in your application. In this chapter, you will learn how to deal with the state in the test and the strategy for creating random test data.

Although HTTP requests may be unpredictable, your test does not have to be. In this chapter, learn how to write predictable network tests on the Punchline application. You can also learn some random jokes along the way!

UI testing allows you to test your application end-to-end without having to manually click to test your application. Use the Espresso library to understand the basics of UI testing.

Part 3: TDD of legacy projects

Now that you understand TDD and have access to different tools, you will learn how to apply these techniques to projects that were not created with TDD and do not have sufficient test coverage. In the process of becoming a TDD expert, you will work through the Furry Coding Companion Finder.

Automated testing can help catch errors in all applications, including legacy applications. Learn how to resolve technical debt and apply testing techniques.

When dealing with legacy applications and writing UI tests with Espresso, start using the Coding Companion Finder application.

Once you have done some testing on the legacy application, you don’t have to be afraid of refactoring the legacy application. Learn how to take small steps and move slowly while keeping the test suite green when making changes to the application.

Your test is also code. In this chapter, you will learn how to refactor your application code and test code to make your tests reliable and maintainable.

Learn through tutorials to learn about multiple methods of processing test data in Android testing. In this chapter, you will explore various methods of using test data in testing.

Explore what it means to continuously integrate your tests and the tools you can use to implement it. You will learn about the advantages and disadvantages of different CI strategies in this chapter.

Set boundaries in your tests and use strategies to help interact with other libraries and parts of the Android framework.


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


Source link