Creating a Test Class
The most convenient way to write unit tests is within a testing framework. The framework makes it easier to write and run a suite of tests together and see their output in Android Studio.
JUnit is almost universally used as a testing framework on Android and has convenient integrations into Android Studio. Your first job is to create a class for your JUnit tests to live in. To do this, open up SoundViewModel.kt and key in Command-Shift-T (Ctrl-Shift-T). Android Studio attempts to navigate to a test class associated with the class you are looking at. If there is no test class (as is the case here), you are given the option to create a new test class (Figure 20.1).
Figure 20.1 Trying to open a test class
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.