Created
June 21, 2023 09:27
-
-
Save kaszabimre/7309a1ca4c83f57ab48c27d5c5830fea to your computer and use it in GitHub Desktop.
Unit test for the searchUser method in the ViewModel class, utilizing the MockKMP for verification. The test ensures that when a mock username is provided, the method returns a non-empty list with the user. Mock objects and assertions are used to validate the expected behavior.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Test | |
fun `given mock username when searchUser called then returns non-emptyList with the user`() = runTest { | |
// Given | |
val userName = MockData.userName | |
everySuspending { action.searchUser(isAny()) } returns Unit | |
every { store.getUsers() } returns flowOf(listOf(MockData.user)) | |
every { store.isFetchingFinished() } returns flowOf(true) | |
// When | |
viewModel.searchUser(userName) | |
// Then | |
val result = viewModel.state.first() | |
assertEquals(userName, result.data.first().login) | |
verifyWithSuspend { | |
viewModel.searchUser(isAny()) | |
viewModel.setState(isAny()) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment