Anyone faced an issue where testing a compose UI d...
# compose
m
Anyone faced an issue where testing a compose UI doesn;t launch the compose itself, yet the test keeps on running [Contd in thread]
class SampleUITesting { @get:Rule val composeTestRule = _createAndroidComposeRule_<ComponentActivity>() @Before fun setup() { composeTestRule.setContent { Box(modifier = Modifier._fillMaxSize_()) { Column( verticalArrangement = Arrangement.spacedBy(12.dp), modifier = Modifier._align_(Alignment.Center) ) { val context = LocalContext.current Button( onClick = { Toast.makeText(context, "Clicked!", Toast._LENGTH_SHORT_).show() } ) { Text(text = "Button") } Button(onClick = { }) { Text(text = "Clicked") } } } } } @After fun tearDown() { } @Test fun perform() { Log.d("ComposeUITesting", "Started") composeTestRule._onNodeWithText_("Button")._performClick_() composeTestRule._onNodeWithText_("Clicked!")._assertIsDisplayed_() } }
On running the test I just get 2 popups to allow the app to be installed on the device and this keeps running. One wierd thing that I observed was when I force stopped the app from settings the test stopped. But I never see a UI being shown while test is running
p
Is the UI using progress bar or some sort of infinite animation. I think I remember something like that, where you had to replace compose animator by a fake in order to be able to run the test, or remove the progress bar when in tests
c
Toast is not a composeable. You cannot assert it with the compose rule.
m
@Pablichjenkov the compose ui is very simple as shown in the setCkntent method... No loaders
@Chrimaeon even though I remove the toast It behaves the same
p
Ah sorry, I replied without reading your code. Other than that issue I mentioned, I haven't seen any similar to yours.
m
I am able to run this on emulator now.. but not on real device