Chapter 21 Unit Testing and Audio Playback
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 21.2).
Figure 21.2 Trying to open a test class
Choose Create New Test... to create the new test class. Select JUnit4 for your testing library and check
the box marked setUp/@Before. Leave all the other fields as they are (Figure 21.3).
Figure 21.3 Creating a new test class
Click OK to continue to the next dialog.
The last step is to choose what kind of test class you will create. Tests in the androidTest folder are
integration tests. Integration tests run on an Android device or emulator. The advantage of that is that
you can test any behavior of your app at runtime. The downside is that since they must build and run an
APK on a device, they take forever to run. (See the section called For the More Curious: Espresso and
Integration Testing for more about integration tests.)
Tests in the test folder are unit tests. Unit tests are run on your local machine, without any of the
Android runtime available. Leaving out that baggage makes them quick.
Unit tests are the smallest kind of test you can write: a test of one component by itself. They should
not need your entire app or a device to run, and they should run quickly enough for you to run them
repeatedly as you work. So choose the test folder for your test class (Figure 21.4) and click OK.