Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Android Model-View-Intent with Unit Tests - FeedViewTest.kt Mocks
@ExperimentalCoroutinesApi
@ExtendWith(FeedViewTestExtension::class)
class FeedViewTest(
val testCoroutineDispatcher: TestCoroutineDispatcher,
val testCoroutineScope: TestCoroutineScope
) {
private fun FeedViewTestCaseStream() = feedViewTestCaseStream()
private lateinit var test: FeedViewTestCase
private val repository = mockkClass(FeedRepository::class)
@ParameterizedTest
@MethodSource("FeedViewTestCaseStream")
fun `FeedView`(feedViewTestCase: FeedViewTestCase) = testCoroutineDispatcher.runBlockingTest {
test = feedViewTestCase
mockComponents(test)
val viewModel = FeedViewModel(
coroutineScopeProvider = testCoroutineScope,
repository = repository
)
...
}
private fun mockComponents(test: FeedViewTestCase) {
coEvery {
repository.getMainFeedNetwork(any(), any())
} returns mockGetMainFeedList(test.status, test.mockFeedList)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment