Test-Driven Development in Android

Jan 24 2023 Kotlin 1.6, Android 12, AS Bumblebee 2021.1.1

Part 1: Unit Tests

3. Build Unit Tests

Episode complete

Play next episode

Next
Save for later
About this episode
See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 2. Do Red-Green-Refactor Next episode: 4. Set Up JUnit

This video Build Unit Tests was last updated on Jan 24 2023

In this and the following episodes you are going to create your first unit test in android, as mentioned before unit tests are meant to test isolated part of your application without worrying about external dependencies. They are at the bottom of our testing pyramid which means that we should create as much of them as we need since they are the fastests to execute and usually the easiest to implement.

But, before writing any tests or compiling any release candidate application you need to understand that there are different kinds of tests and how they are classified.

And that is where the testing pyramid comes in handy, because it helps us easily visualize the different kinds of tests there are and how many of them to use.

It is basically tells us that there should be a big amount of small unit tests, a few integration tests and even fewer UI tests.

As mentioned before, unit tests are meant a test isolated parts of your application and their behavior without worrying about any external dependencies.

They are at the bottom of our testing pyramid which means that we should create as much of them as we need since they are the fastest to execute and -usually- easiest to implement.

Throught this section and the next one you will work on an application called cocktail game. With this application you will have fun with a trivia application about cocktails. You will show the user an image and the user will have to guess the name of a cocktail. For example, this one. And I guessed correctly. The game will keep track of the current score and will save the highest score to shared preferences. Next one. Im gonna guesss. This one. This is wrong. This is wrong. This is wrong. I dont know anything about cocktails. And this one is correct. So my current score is higher that the highest score so the highest score is updated. Easy right?

To build this application you will use test driven development, which means that before building an application you will create a test for that feature, see it fail, you will then build that feature and see your test pass. For example, lets say that I want to create a feature of displaying a picture to your user. You will create a test for displaying a question without any functionality, you will see then the test fail, you will create the functionality to display the question and then you will see the test pass.

That’s is for this episode, in the next one you will see how to set up junit to create unit tests in Android.