Skip to content

Instantly share code, notes, and snippets.

@alexzaitsev
Created January 27, 2023 15:00
Show Gist options
  • Save alexzaitsev/dd734a601304ca6b4b4e6dccd54e2e80 to your computer and use it in GitHub Desktop.
Save alexzaitsev/dd734a601304ca6b4b4e6dccd54e2e80 to your computer and use it in GitHub Desktop.
Dummy test to demonstrate Flow testing
package com.example.domain.usecase
import app.cash.turbine.test
import com.natpryce.hamkrest.assertion.assertThat
import com.natpryce.hamkrest.equalTo
import kotlinx.coroutines.flow.flowOf
import kotlinx.coroutines.test.runTest
import org.junit.Test
class DummyTest {
class UseCase {
operator fun invoke(input: String) = flowOf(input)
}
fun produceSut() = UseCase()
@Test
fun `invoke() emits data with correct attribute anyPendingTxs true`() = runTest {
// arrange mocks, create sut
val sut = produceSut()
// act
val result = sut("input")
// assert
result.test {
assertThat(awaitItem(), equalTo("input"))
awaitComplete()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment