Duplication between BDD and Unit tests

I got this e-mail recently from a blog reader, and decided to share the answer as it might be interesting to others as well:

I listened to your podcast with Scott Hanselman and the discussion touched on the mix of unit tests and BDD acceptance tests, but didn’t really go as far as to offer guidance on where each is really best suited.

Since the BDD tests are integration tests it would seem that for ultimate confidence in the BDD tests as a regression suite they should cover all of the corner cases that the unit tests cover where possible (strange input cases that lead to null references, divide by zero, zero, one, edge case testing, etc) and be exposed to the BA’s to ensure that the code is handling these as expected. This seems to require essentially a near duplication of the cases handled in unit tests to achieve this level. The tests in the unit tests are still useful as they give guidance to developers on which layer the expectation is failing at, especially if the tests are layered with mocks stuffed with the correct behaviors at higher levels.

All of the examples of BDD I’ve seen follow mostly the happy path with only an occasional nod to the unhappy path and don’t seem to go into as many corner cases and essentially code coverage as unit tests too, but this feels incomplete.

I saw this article referenced in the show note comments, but it also felt incomplete

I’m curious if you have any advice or good examples of projects covered by both BDD and unit tests that achieve a good mix.

Continue reading

Dark arts of TDD explained

Growing Object Oriented Software, Guided by Tests, by Steve Freeman and Nat Pryce is a TDD book, but unlike any other on the market today. First of all, the book deals mostly with advanced unit testing topics, such as designing tests for readability and mocking, and addresses many common stumbling points that people experience with unit testing a few years after they started their journey, such as applying unit testing in multi-threaded and asynchronous environments. Second, it explains and demonstrates in practice the dynamics of designing software through TDD, which is still a dark art for many programmers. And third, it gives the reader insight into Freeman’s and Pryce’s brains, which is why this book is a must-read for anyone serious about unit testing, even to people that have been doing it in the last century. Continue reading

How to test asynchronous systems efficiently

I got this e-mail from a reader today:

I don’t know how can I test asynchronous systems. We develop Voice Communication System applications and everything is based on (asynchronous) request-response. I’m trying to write unit tests for such application […] What is the preferable way to do it? Here I think I must test the whole system chain…

Continue reading

Mocks are not about isolation, but about responsibilities

Last week at CITCON Europe Steve Freeman organised a session on mock objects focusing on the original ideas and what mock objects should be used for. Freeman started by disagreeing with the established view of mock objects as isolators for unit testing, advising developers to use mocks for object design and specifying responsibilities. Continue reading