Flaky tests · Scenario
Fails only when tests run in parallel
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Since you turned on four parallel workers, cart tests fail at random: one expects 1 item and finds 3, another's 'remove item' can't find its item. Run alone, every test passes. What's happening?
Then
Follow-ups the interviewer asks next
- What could be shared between tests running at the same time?
- How do you confirm which test is affecting which?
- How would you fix it if you can create users freely?
- And if the environment has only five test users?
- The cart is stored on the server, per user. Does a new browser context help?
- How do you design tests so this can't come back?
The answer
What a strong answer covers
- Shared things: the same user account (server-side cart, orders, wallet), the same product with limited stock, global settings or feature flags a test changes, static variables in the framework, the same download folder, the same email inbox.
- Confirms: report timestamps and logs show which tests ran together and as which user; run two suspects in parallel on purpose.
- Cause here: every cart test logs in as
qa_user1@test.infrom one config value; the cart lives on the server per user, so a fresh browser context doesn't isolate it. - Fix: one user per worker (picked by worker or thread index) or a new user per test through an API; empty the cart through the API in setup; products with enough stock, or created per test.
- Few users: a pool where tests lock and release accounts, and no more workers than users.
- Rule: every test creates or owns its data; none assumes an empty start it didn't make.
The red pen
Common traps
Avoid:turning parallel runs off; ordering tests with priority or dependsOnMethods; emptying the cart at the end of each test (another test may be in the middle of using it).
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.