Waiting & flakiness · level 3 of 5 · PipelineHQ
A sleep is a guess about timing. A retrying assertion waits exactly as long as needed, no more, no less.
Saving a contact takes about 700ms, so this test sleeps before checking the toast. It works, but it is slow and fragile.
Remove the sleep. Let the assertion wait for the toast instead, it retries until the toast appears.
Refactor without weakening
This test passes but it is written badly. Clean it up, it must stay green and still catch every bug.
We break each one in a copy of the app. Your cleaned-up test has to fail on every copy.