Skip to the editor

The suite only passes in one order

State across pages · level 4 of 5 · Nimbus

A test that borrows state from an earlier test is not independent. Run the suite in reverse and the borrowing breaks, give every test its own setup.

The problem

Two tests, both green, until they run in a different order. The first test stashes the credentials in a shared variable, and the second test reads them. Run the second one first and it has nothing to work with, so it fails.

Give each test its own credentials so either can run alone, in any order. Do not share state between tests.

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.

Done when

  • Every test passes on its own, in any order.
  • No state shared between tests.

What this test covers

  • Login accepts any password

We break nothing here. Grading runs the suite three times and in reverse order.

Loading the editor…