SpecFlow/BDD for Unit Tests?

Nicko-Mctricko picture Nicko-Mctricko · Nov 11, 2010 · Viewed 7k times · Source

Seems like the internet doesn't have a definitive answer, or set of principles to help me answer the question. So I turn to the great folk on SO to help me find answers or guiding thoughts :)

SpecFlow is very useful for BDD in .NET. But when we talk about BDD are we just talking integration/acceptance tests, or are we also talking unit tests - a total replacement for TDD?

I've only used it on small projects, but I find that even for my unit tests, SpecFlow improves code documentation and thinking in terms of language. Converseley, I can't see the full code for a test in one place - as the steps are fragmented.

Now to you..........

EDIT: I forgot to mention that I see RSpec in the RoR community which uses BDD-style syntax for unit testing.

Answer

Jason Evans picture Jason Evans · Nov 11, 2010

I've recently started to use SpecFlow for my BDD testing, but also, I still use unit and integration tests.

Basically, I split the tests into seperate projects:

  • Specs
  • Integration
  • Unit

My unit tests are for testing a single method and do not perform any database calls, or external references whatsoever. I use integration tests for single method calls (maybe sometime two) which do interact with an external resources, such as a database, or web service, etc.

I use BDD to describe tests which mimick the business/domain requirements of the project. For example, I would have specs for the invoice generation feature of a project; or for working with a shopping basket. These tests follow the

As a user, I want, In order to

type of semantics.

My advise is to split your tests based on your needs. Avoid trying to perform unit testing using SpecFlow.