Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When using BDD specifications in a .NET project, why would one use both SpecFlow *and* MSpec?

I repeatedly hear BDD enthusiasts advocate using both SpecFlow and MSpec in the same project.

  • Apparently SpecFlow is more suitable for outside-in/UI tests. (For example, web tests which simulate mouse-clicks, etc, using WatiN or something similar.)

  • Apparently MSpec is more suitable for unit-tests.

Now my question is - why use two frameworks which are incredibly similar and do virtually the same thing?

Why not instead:

  • Choose one BDD framework and stick with it. Use it for outside-in/UI tests, as intended,
  • Write your unit-tests normally, with an established unit-testing framework (such as NUnit, MSTest, etc)?

I thought the reason we adopt BDD is so we can test behaviours, which are driven externally, by means of integration tests.

I don't see how/why this applies to unit tests.

like image 978
Jonathan Avatar asked May 11 '11 01:05

Jonathan


2 Answers

I agree with Darren. Generally I think this is partly a cultural/learning thing.

If you want to have the business actively collaborating on the executable specification you do, you need business readability. So you need a BDD tool, like SpecFlow.

For unit testing, the "business" is you or the other developers in your team, so the only constraint is that you have to write your unit tests in a way that other developers can understand it (e.g. it's not a totally obscure code).

So whether you use NUnit, MSpec or even SpecFlow for unit testing should be decided based on what your team feels comfortable and efficient. It is very hard to give any concrete advise from outside. If your team is fluent with NUnit and just learning BDD/SpecFlow, I would keep the unit testing with NUnit. If your team is already addicted to given-when-then, it makes sense to try a few unit-level BDD tool and see what your team likes the best.

Personally I would be very careful using a plain-text-based (external DSL) tool (e.g. SpecFlow) for unit testing, but would rather go for tools that use fluent interfaces (internal DSL), like MSpec. But I know about teams that use SpecFlow for unit testing successfully.

like image 101
Gaspar Nagy Avatar answered Oct 14 '22 00:10

Gaspar Nagy


I don't think your question is completely valid, because MSpec and SpecFlow are not incredibly similar and do not do virtually the same thing. Just look at the two side-by-side... they look nothing alike, and they work completely different.

The best advice I can give to you is to read The RSpec Book, which shows in detail how to do testing in Ruby with a combination of RSpec and Cucumber. Many of the ideas in this book can be applied to MSpec/SpecFlow in C# and .Net. It's the best explanation of the BDD process that I've read.

like image 45
Darren Avatar answered Oct 14 '22 00:10

Darren