Hello! Test problem here! test methods cannot be ...
# compose
a
Hello! Test problem here! test methods cannot be annotated wit
@Composable
but they need some composable code... code in 🧵
Test case:
Copy code
@Test
fun assertIsDisplayed_ResourceTest() {
  val textRes = R.string.app_name
  composeTestRule.setContent {
    val text = stringResource(id = textRes)
    TextComposable(text = text)
  }

  composeTestRule.assertIsDisplayed(text = textRes)
}
Method `assertIsDisplayed`:
Copy code
@Composable
fun ComposeTestRule.assertIsDisplayed(
  useUnmergedTree: Boolean = false,
  @StringRes text: Int,
  substring: Boolean = false,
  ignoreCase: Boolean = false
): SemanticsNodeInteraction {
  return onNodeWithText(
    text = stringResource(id = text),
    substring = substring,
    ignoreCase = ignoreCase,
    useUnmergedTree = useUnmergedTree
  ).assertIsDisplayed()
}
As this method uses
@StringRes
as a param, I need to use
stringResource()
to load it as
String
but for that i need the
@Composable
annotation
whenever I try to run the test:
Copy code
java.lang.Exception: Method assertIsDisplayed_ResourceTest should have no parameters
a
Here's the correct way:

https://youtu.be/kdwofTaEHrs?t=217â–¾

a
yeah, endup with that solution 😅