Test-Driven Development in Android

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

Part 2: Integration Tests

14. Last Integration Test

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: 13. Master Integration Tests Next episode: 15. Refactor Code

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: 14. Last Integration Test

In the previous episode you ensured that you could save the correct data. Now you want to make sure that you actualy get the correct data when calling the database. So, our last test is going to do just that.

Let me scroll down a little bit. Call this method:

@Test
fun getWishListReturnsCorretData(){

}

As usual we will create our wishlist:

val wishlist = Wishlist("Victoria",
        listOf("RW Android Apprentice Book", "Android phone"), 1)

then:

wishlistDao.save(wishlist)

We’re going to create a mockup server just like the one we created before so im going to copy and paste:

val mockObserver = mock<Observer<Wishlist>>()
viewModel.getWishlist(1).observeForever(mockObserver)
verify(mockObserver).onChanged(wishlist)

Again we’re creating a new wishlist with some test data and an id of . We’re using the save method of the wishlistDao to save the wishlist. Then we create an observer and finally we call the wishlist method and verify that the getWishlist that we return with this method is the correct one.

Execute your test. It fails as expected.

Open your DetailViewmodel class and instead of just passing any id. Pass the id that we received as a parameter.

Execute all of your tests and they all pass. Nice.