What BDD frameworks for .NET / C# are actively maintained? Let’s try some of them out!

I will try actively maintained projects that:

  • Is open source
  • Is available on NuGet
  • Has published a release this year

I group the frameworks into two categories:

  • Behavior-driven development (BDD)
    • Specifications written and read by developers.
  • Specification by example (SBE)
    • Specifications written and read by developers, testers and business analysts (Three Amigos).

Frameworks for Behavior-driven development:

Frameworks for Specification by example:

I’ll use ReSharper as my testrunner when it’s possible.

You can view the code at https://github.com/hlaueriksson/ConductOfCode

The subject

The stack, a last-in-first-out (LIFO) collection:

The specifications will test the behavior of:

  • Empty vs nonempty stack
  • Peek() and Pop() methods
  • InvalidOperationException

Stack

Now I will let the code speak for itself…

LightBDD

LightBDD

Console output during test execution:

FEATURE: [LIFO] Stack feature
  In order to support last-in-first-out (LIFO) operations
  As a developer
  I want to use a stack
SCENARIO: [Empty] Empty stack
  STEP 1/4: GIVEN an empty stack...
  STEP 1/4: GIVEN an empty stack (Passed after <1ms)
  STEP 2/4: THEN it has no elements...
  STEP 2/4: THEN it has no elements (Passed after 1ms)
  STEP 3/4: AND it throws an exception when calling pop...
  STEP 3/4: AND it throws an exception when calling pop (Passed after 2ms)
  STEP 4/4: AND it throws an exception when calling peek...
  STEP 4/4: AND it throws an exception when calling peek (Passed after <1ms)
  SCENARIO RESULT: Passed after 17ms
SCENARIO: [Not empty] Non empty stack
  STEP 1/7: GIVEN a non empty stack...
  STEP 1/7: GIVEN a non empty stack (Passed after 1ms)
  STEP 2/7: WHEN calling peek...
  STEP 2/7: WHEN calling peek (Passed after <1ms)
  STEP 3/7: THEN it returns the top element...
  STEP 3/7: THEN it returns the top element (Passed after 5ms)
  STEP 4/7: BUT it does not remove the top element...
  STEP 4/7: BUT it does not remove the top element (Passed after <1ms)
  STEP 5/7: WHEN calling pop...
  STEP 5/7: WHEN calling pop (Passed after <1ms)
  STEP 6/7: THEN it returns the top element...
  STEP 6/7: THEN it returns the top element (Passed after <1ms)
  STEP 7/7: AND it removes the top element...
  STEP 7/7: AND it removes the top element (Passed after <1ms)
  SCENARIO RESULT: Passed after 17ms

View the commit on GitHub: 513f0fce52ce63073fe662f9a1279b879399d99d

HTML reports can be enabled with configuration:

LightBDD

Thanks Wojtek for the Pull Request

Machine.Specifications (MSpec)

Machine.Specifications (MSpec)

View the commit on GitHub: 217e02c329bb8590e3aade6f5d0ff44d1ba14e6e

NSpec

Run the specs from the console:

.\packages\nspec.1.0.7\tools\NSpecRunner.exe .\ConductOfCode\bin\Debug\ConductOfCode.dll

NSpec

View the commit on GitHub: dc8a8b5f65128a3a95920911cb0af60fdfd7c3a1

SpecsFor

SpecsFor

View the commit on GitHub: 96057b2d794d54dba98ed17c09ae26b3b91f37af

xBehave.net

xBehave.net

View the commit on GitHub: a11c641a66d284d3ef508358e371475e4056a339

Concordion.NET

Why do I get the error “no specification extensions defined for: Concordion.NET.Internal.SpecificationConfig”?

Concordion.NET

Output is written to your temp folder:

C:\Users\<username>\AppData\Local\Temp\ConductOfCode\Concordion

Concordion.NET

View the commit on GitHub: 33631d54be3986b6263d7a22fd2888513a920ea6

SpecFlow

SpecFlow

View the commit on GitHub: 3c468931d7eb71e0fff2840200a25f67f5a0d273

Popularity

At the time of writing, based on the number of downloads from NuGet, the most popular frameworks are:

  1. SpecFlow
  2. Machine.Specifications (MSpec)
  3. SpecsFor
  4. NSpec
  5. xBehave.net
  6. LightBDD
  7. Concordion.NET