Testing Legacy Apps on Android
In this course you are going to learn how to apply the test-driven development practices your learned in “Test-Driven Development in Android” on legacy Android apps. You will learn how to determine your limits when testing legacy code, how to add tests to a legacy app with no test coverage and how to refactor your legacy code for testability. By Aldo Olivares.
Who is this for?
This course is intended for intermediate and advanced level Android Developers that have a good background in Android Development, Kotlin and Software Development. Experience with testing libraries such as Mockito and JUnit is recommended but not required.
Covered concepts
- Adding Legacy Tests
- Mock Data
- Writing Legacy Tests
- Refactoring Code for Testability
- Koin and Mockito
- Nitrogen and Shared Tests
- Unt Tests with Retrofit
Part 1: Testing Legacy Android Apps
In this episode I am going to give you a brief introduction to Test-Driven Development in Android over the years. We are also going to explore the problems that some legacy code has that makes it difficult to test.
In this episode I am going to give you a quick introduction to the project you are going to use. You are also going to add the appropriate code to make sure the app is ready for testing.
When adding tests to a legacy app with no test coverage, the first step is to add tests around the functionality where you are going to be adding a feature. In this episode you are going to add tests around the “search for companion” section of your app.
Mock web server sets up a local web server that runs on a random port on an Android Device. To use this local web server along with retrofit you need to point your retrofit instance at this local web server instead of the one at petfinder. Here I am going to show you how to do just that.
Before working with our petfinder service we need to know how our data looks like. In this episode I am going to show you the GET response that we are going to use to receive a pet companion from our API.
Now that you know how your data looks like and have a file with a mock response you are going to create a method that automatically reads your file and returns its contents.
Next we are going to write a test to verify that we have the appropriate navigation between our screens.
One thing you should always look for when writing tests is to refactor every time it is possible so you don’t repeat yourself. In this lesson you are going to refactor some methods using the @Before and @After annotations.
In the final episode for this course you are going to write a test for a new feature following the red green refactor steps of test-driven development.