Created
March 17, 2021 17:22
-
-
Save igorescodro/9919da0c035e30fef03bd7eb6816b03e to your computer and use it in GitHub Desktop.
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
internal class MyComposableTest { | |
@get:Rule | |
val flakyRule = FlakyTestRule() | |
@get:Rule | |
val composeTestRule = createEmptyComposeRule() | |
private lateinit var scenario: ActivityScenario<ComponentActivity> | |
@Before | |
fun setup() { | |
scenario = ActivityScenario.launch(ComponentActivity::class.java) | |
} | |
@After | |
fun tearDown() { | |
scenario.close() | |
} | |
@Test | |
@AllowFlaky(attempts = 5) | |
fun test_TitleIsShownWhenLoaded() { | |
initComposable(state = MyState.Loaded) | |
composeTestRule.onNodeWithText("Title").assertIsDisplayed() | |
} | |
@Test | |
fun test_TitleIsNotShownWhenError() { | |
initComposable(state = MyState.Error) | |
composeTestRule.onNodeWithText("Title").assertIsNotDisplayed() | |
} | |
private fun initComposable(state: MyState) { | |
scenario.onActivity { activity -> | |
MyTheme { | |
activity.setContent { | |
MyComposable(state = state) | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment