Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save husaynhakeem/9cfa0c7ed63736a74e0312c2c16324f5 to your computer and use it in GitHub Desktop.
Save husaynhakeem/9cfa0c7ed63736a74e0312c2c16324f5 to your computer and use it in GitHub Desktop.
@Test
fun shouldSendData() {
val scenario = FragmentScenario.launchInContainer(FragmentB::class.java)
// Register result listener
var receivedData = ""
scenario.onFragment { fragment ->
fragment.parentFragmentManager.setFragmentResultListener(
KEY,
fragment,
FragmentResultListener { key, result ->
receivedData = result.getString(KEY_DATA)
})
}
// Send data
onView(withId(R.id.send_data)).perform(click())
// Verify data was successfully sent
assertThat(receivedData).isEqualTo("value")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment