As we discussed in the previous recipe, we cannot use Android components in unit tests. This is why we are able to run them faster, and without any device. If you want to use Android components in your tests, there are two options:
- Write integration tests, which run on your device or emulator.
- Use a mocking framework, such as Mockito, which basically mocks the Android SDK components so that you can use them without any device or emulator, just like any other unit test. The benefit of a mocking framework is that it takes a lot less time to run the tests, as the tests are basically unit tests only. Here's an accurate definition of a mock object by Vogella:
"A mock object is a dummy implementation for an interface or a class in which you define the output of certain method calls. Mock objects are configured to perform a certain behavior...