Search code examples
unit-testingtestingcucumbertddbdd

Testing Application State in BDDs


Suppose I have an API that has three steps:

  1. Create Quote
  2. Add products to quote
  3. Create Payment
  4. Charge
  5. Mutate (updates the document in my database)

I am writing a BDD for this API. My question is, should I check if the document is updated after the above steps have passed? Or that the document should not be mutated if any of the above steps have failed?

I ask this question as BDDs are for the product to read. So okay, the product should be able to see that the charge was successful, but does the product need to see if the database was updated? Isn't it too for technical for them?

What would be the correct way to test such steps, especially if they are the last step of your action chain?


Solution

  • Should I check if the document is updated after the above steps have passed? Or that the document should not be mutated if any of the above steps have failed?

    The answer is "yes".

    You should check if the document was updated when all steps passed.

    You should have additional scenarios highlighting the fact the document is not updated if any of the steps fail. In fact, this feels like 5 separate scenarios:

    1. All goes well, document is updated
    2. First step fails, document not updated.
    3. First step passes, but second step fails. Document not updated.
    4. First and second steps pass, but third step fails. Document not updated.
    5. First through third steps pass, but the "Charge" step fails. Document not updated.

    While the product team is mainly thinking about scenario 1, if you introduce them to scenarios 2-5 you will quickly learn that they care about these scenarios as well.