What other scenarios have you found?

Local JUnit 5 PagedList Test

@saied89 shared this solution in this googlesamples/android-architecture-components issue. I’ve implemented the mocked PagedList in the Coinverse Open App in order to local unit test a ViewModel using Kotlin, JUnit 5, MockK, and AssertJ libraries.

LiveData — To observe the LiveData from the PagedList I’ve used Jose Alcérreca’s implementation of getOrAwaitValue from the LiveDataSample sample app under Google's Android Architecture Components samples.

The asPagedList extension function is implemented in the sample test ContentViewModelTest.kt below.

Threading — InstantExecutorExtension.kt is required for JUnit 5 when using LiveData in order to ensure the Observer is not on the main thread. Below is Jeroen Mols’ implementation.

PagedListTestUtil.kt

LiveDataTestUtil.kt

ContentViewModelTest.kt

InstantExecutorExtension.kt

--

--

Open Sourcer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store