Waiting & flakiness · level 4 of 5 · PipelineHQ
A fixed sleep is a bet on how long the app takes. Wait for the result you expect, and the flakiness disappears.
This test creates a contact and checks the toast, and it passes, sometimes. Saving takes around 700ms, but the test only sleeps 400ms before asserting, so on a slow run the toast is not there yet and the test goes red.
Remove the sleep. Let the assertion wait for the toast instead, it retries until the toast appears, however long the save takes.
Debug the flaky test
This suite is unreliable. Run it a few times to see it fail sometimes, then make it stable without using sleeps or relying on the order tests run in.
We break nothing here. Grading runs the suite three times and in reverse order.