james
09/20/2021, 7:31 AMK Merle
09/20/2021, 8:01 AMziv kesten
09/20/2021, 9:05 AMZach Klippenstein (he/him) [MOD]
09/20/2021, 4:29 PMColton Idle
09/21/2021, 3:46 AMYou can write unit tests for UI🤔 With jetpack compose though you still technically need to run those unit tests on the device right?
K Merle
09/21/2021, 6:26 AM@Test
fun should_call_sign_out_once_when_sign_out_button_clicked() {
with(composeTestRule) {
setContent { SignOutScreen(viewModel = viewModel) {} }
val signOutButtonText = activity.getString(R.string.sign_out_button)
onNodeWithText(signOutButtonText).performClick()
verify { viewModel.signOut() }
}
}
ziv kesten
09/21/2021, 7:53 AMZach Klippenstein (he/him) [MOD]
09/21/2021, 6:31 PMWith jetpack compose though you still technically need to run those unit tests on the device rightProbably, although you may be able to run them with robolectric.
If you need an activity/device/emulator I don’t see how it is a unit test and not a UI test.They are different axes. A “unit test” tests a “unit” of code, as opposed to an integration test which tests how multiple components interact. There are other types of tests on this axis as well (e.g. functional). A “unit” can be a non-UI bit of logic, or a single UI component, for example. A “UI test” tests some UI. That may be a single component (i.e. a unit UI test) or a whole navigation flow. Typically UI tests are ran on an emulator or device, although it might be possible in the future to run UI tests without a device/emulator (typically called “host-side”).
ziv kesten
09/21/2021, 8:17 PMZach Klippenstein (he/him) [MOD]
09/21/2021, 8:56 PMjames
09/24/2021, 4:55 AM