Skip to content

Instantly share code, notes, and snippets.

@fmedlin
Created April 27, 2018 18:42
Show Gist options
  • Save fmedlin/879821a00f927964e8d11a998278312a to your computer and use it in GitHub Desktop.
Save fmedlin/879821a00f927964e8d11a998278312a to your computer and use it in GitHub Desktop.
Robolectric Examples
/**
* The dialog returned by ShadowDialog.getLatestDialog() does not expose much for testing.
* However, getting an AlertDialog shadow can help.
*/
@RunWith(RobolectricTestRunner::class)
class WebLoginActivityTest {
private lateinit var activity: SomeActivity
@Before
fun setup() {
activity = Robolectric.setupActivity(WebLoginActivity::class.java)
}
@Test
fun itDialogsLoginErrors() {
activity.dialogError("Some Title", "Some message that we display")
val dialog = ShadowDialog.getLatestDialog() as AlertDialog
shadowOf(dialog).apply {
title shouldEqual "Some Title"
message shouldEqual "Some message that we display"
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment