Test-Driven Development in Android

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

Part 2: Integration Tests

11. Create Test Class

Episode complete

Play next episode

Next
About this episode

Leave a rating/review

See forum comments
Cinema mode Mark complete Download course materials
Previous episode: 10. Build Integration Tests Next episode: 12. Create First Test Method

Get immediate access to this and 4,000+ other videos and books.

Take your career further with a Kodeco Personal Plan. With unlimited access to over 40+ books and 4,000+ professional videos in a single subscription, it's simply the best investment you can make in your development career.

Learn more Already a subscriber? Sign in.

Transcript: 11. Create Test Class

For now close all your files, close all your tabs and create a new test package for your integration tests. And create a new package for your integration tests by switching to the project view. Open the app package, source, select a new directory and name it androidTest.

And in here we are going to create the same package structure that we have in the other folders. So, new directory, java, and in here new package:

com.raywenderlich.android.wishlist 

And in here we are going to be creating the integrtion tests for our app. The first one is going to be DetailViewModelTest.

There is also a shortcut that you can use to create the tst for a certain class. Open your main package -> java -> DetailViewModel. Let me delete this class.

If you want to create a test for a certain class simply press CMD + SHIFT + T, create new test, leave the default options, notice how the test keyword is already appended to the end of our class name. OK

In here select your androidTest package since we want to create an integration test. I’m going to delete this import, I’m also going to delete this internal keyword, add braces, and you will need to add a rule for your tests:

@get:Rule
var instantTaskExecutorRule = InstantTaskExecutorRule()

This is the same test rule that you use for mockito to make sure that when you are using live data and viewmodel it is all run synchronously in your tests.

Nice!