Created
February 21, 2021 11:45
-
-
Save shredderskelton/d5f971a398d90a7aad8a04d9f0da4f9c to your computer and use it in GitHub Desktop.
Unit Test Hot Flow Take
This file contains hidden or 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
/** | |
* Unit Testing Hot Flows the Android recommended way | |
*/ | |
@Ignore | |
@Test | |
fun `hot flow - hangs`() { | |
runBlocking { | |
val actual = MutableStateFlow("test").single() | |
assertThat(actual).isEqualTo("test") | |
} | |
} | |
@Test | |
fun `hot flow - This job has not completed yet`() { | |
rule.testDispatcher.runBlockingTest { | |
val actual = MutableStateFlow("test").single() | |
assertThat(actual).isEqualTo("test") | |
} | |
} | |
@Test | |
fun `hot flow first - Success!`() { | |
runBlocking { | |
val actual = MutableStateFlow("test").first() // first() cancels the Flow | |
assertThat(actual).isEqualTo("test") | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment