Writing tests for our DataStore instance
Writing tests is crucial in Android development, and in this recipe, we will write some tests for our DataStore instance. To test our DataStore instance or any DataStore instance, we first need to have instrumentation testing set up since we will be reading and writing in actual files (DataStore), and it is vital to verify that accurate updates are being made.
How to do it…
We will start by creating a simple unit test to test our view model function:
- In our unit test folder, create a new folder and call it
test
, and inside it, go ahead and create a new class calledTaskViewModelTest
:class TaskViewModelTest {}
- Next, we will need to add some testing dependencies:
testImplementation "io.mockk:mockk:1.13.3"
androidTestImplementation "io.mockk:mockk-android:1.13.3"
testImplementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:1.5.2"
- Now that we have added the required dependencies...