Testing Worker implementations
Testing your Worker
implementation is crucial, as it helps ensure your code is well handled and your team follows the proper guidelines for writing great code. This will be an integration test, which means we will add our code to the androidTest
folder. This recipe will look into how to add tests for your worker.
Getting ready
To follow along with this recipe, you need to have completed all previous recipes of this chapter.
How to do it…
Follow these steps to get started with testing WorkManager
. We will look at examples in this recipe:
- First, you need to add the testing dependency in your
build.gradle
file:androidTestImplementation("androidx.work:work-testing:$work_version")
In the scenario where something in the API changes in the future, there’s a stable version that you can use, and you can always find that in the documentation by following this link: https://developer.android.com/jetpack/androidx...