Yes, or if you want something testing even more of the stack, you could use AWT Robot to simulate button clicks.
However, honestly, your button click logic should be so simple as to be almost foolproof, so any time you have available to write tests would probably be better spent writing a different kind of test. Specifically, the more important thing to test is that after your state is such that the button has been clicked, that the result rendered by the widget is correct. You can do this by creating a state object that represents the post-click state, and rendering it to a canvas and checking the output against a reference image.
As an added bonus, you are also verifying that the state of your widget is properly hoistable.
ā 2
c
Colton Idle
07/14/2021, 5:06 PM
Love that framing @jim
Looking forward to someone creating a nice screenshot testing framework for compose UI.
š 2
k
Kirill Grouchnikov
07/14/2021, 5:18 PM
Note that on latest versions of macOS you'll need to grant Java runtime extra system-level permissions to use the
java.awt.Robot
APIs (maybe just the ones that move the mouse, or maybe in general)