Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • I usually consider "one reason to fail" to mean only one "when" rather than one "then" (and even then there are exceptions). Consider for instance taking money from an ATM. You get the money, and also your bank account is debited; both of those have to happen at the same time, so should IMO appear in the same scenario. This is pretty typical of transactions. If it's a separate outcome for another stakeholder (deliverable independently), then yes, put them in a separate scenario as it's a different capability that happens to have the same trigger for its behaviour. Commented Sep 12, 2019 at 8:44
  • @Lunivore: I can see what you mean, but I've always thought of BDD tests in respect to the change in state you expect. If a single change of state causes your test to fail for multiple reasons, people will think that test is flaky or unstable. Same rule applies to unit tests as well. You want the failure to be: A) Singular; and B) Easy to identify. Having a single Then gives you that single point of expected failure. If you think about it, a Given is a When that has already happened, so most BDD tests already have more than one When anyhow. Commented Sep 12, 2019 at 11:20
  • You're thinking of BDD's primary purpose as testing. Try thinking of them as automated scenarios and living documentation. If it's done right, it helps people to understand how/why the software works and should prevent bugs. Catching them should be a rare thing. If you're primarily using BDD for regression tests, use more class-level TDD / BDD to help separate concerns and improve quality. And Givens aren't always Whens that have happened; we've frequently for instance set up data without going through the UI or API. It shouldn't matter how a Given is set up (or who did it!). Commented Sep 12, 2019 at 16:25
  • Short version: I value making automated scenarios and unit tests easy to understand when reading them, more than I value making them easy to understand when they fail. They fail less that way. Commented Sep 12, 2019 at 16:31