Setting Up Your Test

Now to build out your SoundViewModel test. Android Studio has created a class file for you, called SoundViewModelTest.kt. (You can find this class under the source set labeled test inside your app module.) The template starts out with a single function called setUp():

    class SoundViewModelTest {

        @Before
        fun setUp() {
        }
    }

A test needs to do the same work for most objects: build an instance of the object to test and create any other objects that object depends on. Instead of writing this same code for every test, JUnit provides an annotation called @Before. Code written inside a function marked @Before will be run once before each test executes. By convention, most JUnit test classes have one function marked ...

Get Android Programming: The Big Nerd Ranch Guide, 4th Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.