Search code examples
nunitbddspecflow

BDD Result: What to do if I expect an error


I'm trying a little bit the BDD approach and I've a question:

I've made a scenario for a fictive bank account:

Scenario: No money as new customer
    Given I'm a customer
    And I've not any deposit
    When I try to withdraw 50 dollars
    Then I should get an error

I'm implementing it with Specflow + NUnit.

I'm a little bit borried by the Then I should get an error. Because currently I've a bool TryWithdraw(double amount).

I can see two way of making it working:

  1. Change the BDD requirement to remove the THEN
  2. Store the result of the WHEN, and check it in the THEN

What would be the correct approach? Is my BDD requirement correct or do I have to store the result?


Solution

  • BDD Tests are like unit tests structured. You have an arrange part, an act part and at the end the assert part:

    • Given = arrange
    • When = act
    • Then = assert

    So storing the result of your act (When I try to withdraw 50 dollars) is complete valid. Then you do your assert based on the result.