https://kotlinlang.org logo
#compose
Title
# compose
m

Mahmoo

02/29/2024, 5:08 PM
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

Pablichjenkov

02/29/2024, 8:06 PM
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

Chrimaeon

03/01/2024, 7:04 AM
Toast is not a composeable. You cannot assert it with the compose rule.
m

Mahmoo

03/01/2024, 6:30 PM
@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

Pablichjenkov

03/01/2024, 6:50 PM
Ah sorry, I replied without reading your code. Other than that issue I mentioned, I haven't seen any similar to yours.
m

Mahmoo

03/04/2024, 4:18 PM
I am able to run this on emulator now.. but not on real device
4 Views