Writing tests for your Paging Source
Writing tests for your implementations is crucial. We will write unit tests for our PagingSource
implementation in this recipe to test our logic. Some tests that might be worth writing are checking when news Paging load failure happens.
We can also test the success state and more. You can follow the pattern to write tests for your project or use case.
Getting ready
To follow this recipe step by step, you need to have followed the Implementing the Jetpack Paging library recipe, and you need to use the PagingJetpackExample
project.
How to do it…
Open PagingJetpackExample
and follow along with this project to add unit tests:
- Add the following testing libraries to your
build.gradle
app:testImplementation 'org.assertj:assertj-core:3.x.x'
testImplementation "org.mockito:mockito-core:3.x.x"
testImplementation 'Androidx.arch.core:core-testing:2.x.x'
testImplementation 'org.jetbrains.kotlinx:kotlinx...