WARNING - This site is for adults only!
This web site contains sexually explicit material:@Test fun `state flow emits new values`() = runTest { val viewModel = MyViewModel() val collector = viewModel.stateFlow.test { viewModel.doAction("Click") // Await the next emission val item = awaitItem() assertEquals("Loading", item.status) // Ensure no extra items came cancelAndIgnoreRemainingEvents() } } A professional Kotlin project separates test sources by type:
It’s time to change that. Welcome to your conceptual . curso de testing kotlin
Use TestDispatcher and advanceUntilIdle() to control time precisely. Module 4: Mocking with MockK (Not Mockito) If you come from Java, you know Mockito. For Kotlin, you need MockK . Why? Because Mockito fails when dealing with final classes (Kotlin classes are final by default) and suspend functions. Mocking a suspend function import io.mockk.coEvery import io.mockk.coVerify import io.mockk.mockk class RepositoryTest { @Test fun `state flow emits new values`() =
import kotlin.test.Test import kotlin.test.assertEquals import kotlin.test.assertNotNull class CalculatorTest { Module 4: Mocking with MockK (Not Mockito) If
Did you find this "curso" useful? Share your biggest testing pain point in the comments below!
import kotlinx.coroutines.test.runTest import kotlinx.coroutines.delay class ApiClientTest {