Friday, March 14, 2008

BDD - Mock then replace

Just re-reading Dan North's article Introducing BDD and realized that I'd forgotten about this section:

At first, the fragments are implemented using mocks to set an account to be in credit or a card to be valid. These form the starting points for implementing behaviour. As you implement the application, the givens and outcomes are changed to use the actual classes you have implemented, so that by the time the scenario is completed, they have become proper end-to-end functional tests.

I must admit I haven't tried this approach yet but it is one that makes sense to me so I think I'll try it because I really think having end-to-end functional tests is very attractive.

Share This - Digg It Save to del.icio.us Stumble It! Kick It DZone

2 comments:

  1. Good get. I did a brief investigation into the AutoMockingContainer to try the "just flick a switch to go to real classes." This turned out (very quickly) to be a bad idea as you need to setup stub values to handle assertions. If a mocking framework was capable of injecting a DB when you switched to end-to-end, this might work, but It would have to be designed from the ground up.

    ReplyDelete
  2. Ahh yes, now that that would be interesting.

    I'm gonna give the whole mock then replace option another try manually. Maybe I'll get the advantage of the mock based design approach and end up with good acceptance tests. Maybe :)

    ReplyDelete