CodePark/ questions / TDD & test design
START PRACTICINGPRACTICE
Backend question · Backend testing › TDD & test design

Which test best follows the idea that a test should have one reason to fail?

'rejects an email that is already registered': registers a user, registers again with the same email and expects a ConflictException

"'rejects an email that is already registered'" is the best choice. It checks one behaviour, so when it fails, its name tells you what broke.

The "'user flow works'" test can fail for four different reasons. It also stops at the first failure, so it hides the rest.


Several
expect calls in one test are fine when they describe one outcome. The real problem is testing several behaviours in one test.