Covering the basics of unit-testing your core logic
Apart from testing our UI layer, we must also test the core logic of our application. This means that we should try to verify as much behavior as possible in terms of presentation logic (testing ViewModel
classes), business logic (testing UseCase
classes), or even data logic (testing Repository
classes).
The easiest way of validating such logic is by writing unit tests for each class or group of classes whose behavior we're trying to verify.
In this section, we will be writing unit tests for the RestaurantsViewModel
class and the ToggleRestaurantUseCase
class. Since these components don't interact directly with the UI, their unit tests will run directly on your local workstation's Java Virtual Machine (JVM), rather than running on an Android device, as our UI tests did.
To summarize, in this section, we will be doing the following:
- Testing the functionality of a
ViewModel
class - Testing the functionality...