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

Brian Donovan

02/07/2022, 5:15 PM
Hey all, trying to write some tests. Can I get some help with the method please. thanks
z

Zach Klippenstein (he/him) [MOD]

02/07/2022, 5:17 PM
Do you have the
androidx.compose.ui:ui-test-junit4
dependency?
b

Brian Donovan

02/07/2022, 5:18 PM
ooohhhhh let me check!!!
yes I do!
z

Zach Klippenstein (he/him) [MOD]

02/07/2022, 5:22 PM
Hm, and since that error message doesn’t offer to import it for you it seems like AS is actually not seeing it.
Do you see that test library in “External Libraries” in the Project pane of AS?
b

Brian Donovan

02/07/2022, 5:26 PM
yep
z

Zach Klippenstein (he/him) [MOD]

02/07/2022, 5:27 PM
if you manually add the import, then run the test on the command line, does that work?
b

Brian Donovan

02/07/2022, 5:34 PM
like this?
h

hfhbd

02/07/2022, 5:41 PM
You can't run an UI test in local unit tests, you need some UI device, eg emulator/real device.
a

Albert Chang

02/07/2022, 5:43 PM
You need to put the code in the "androidTest" directory.
b

Brian Donovan

02/07/2022, 5:44 PM
let me try that
ty guys
z

Zach Klippenstein (he/him) [MOD]

02/07/2022, 5:53 PM
That's not the right package, but yea
m

mattinger

02/07/2022, 9:16 PM
@hfhbd You can run composable tests in a unit test environment using robolectric. There’s definitely some limitations, but you can test a large portion of standard behavior, but what i’ve found is it doesn’t actually do any drawing. So testing things like a custom composable that draws to a canvas, or using .captureToBitmap() doesn’t actually work.
2 Views