Overview - Preserving state between tests
What is it?
Preserving state between tests means keeping certain data or conditions unchanged as you run multiple tests in a row. In Cypress, this often involves saving things like cookies, local storage, or session information so tests can continue smoothly without starting fresh each time. This helps tests run faster and behave more like a real user session. Without preserving state, each test would start from scratch, making tests slower and less realistic.
Why it matters
Without preserving state, tests would have to log in or set up the same data repeatedly, wasting time and making tests fragile. This slows down development and can cause false failures if setup steps fail. Preserving state makes tests more efficient and reliable, reflecting how users actually interact with the app over time. It also helps catch bugs that happen only when state carries over, improving software quality.
Where it fits
Before learning this, you should understand basic Cypress test writing and how tests run independently. After this, you can learn about advanced test organization, custom commands, and continuous integration setups that rely on stable test states.