The Last BDD Framework You'll Ever Need

In .NET land, there are more BDD frameworks than you can shake a stick at.

When evaluating these frameworks, there are several questions to ask:

  • can I actually easily read the specification
  • does it work with our test runner, IDE, CI and reporting?
  • are there any syntactical somersaults required to use it? Looking at you MSpec
  • will the tests be easy to maintain in the future?
  • MOST IMPORTANT OF ALL - will I need to persuade/teach the rest of the team to use it, and how hard will that be?

If you don't want to faff about with the above issues, you can use my approach. I've been using it successfully at a series of different companies with a 100% success rate.

It's called 'Inline Gherkin Comments' and it looks like this:

public void PawnsCanThreatenDiagonally()  
    //Given a chessboard
    var chessBoard = new ChessGame(layout);        
    //And there is a pawn with an enemy piece in a diagonally forward square
    chessboard.Move("d2 d4");
    chessboard.Move("e7 e5");

    //When the allowed moves of the pawn are considered
    var moves = chessBoard["d4"].Piece.PotentialMoves();            
    //Then the pawn can move to the square of the enemy piece
    Assert.True(moves.Select(move => move.Dest).Contains(chessBoard["e5"]));

Why is this any different from the other frameworks?

  • The comments specify the behaviour of the system, the code implements it. This prevents errors where misread requirements or refactoring can result in the specification being changed.
  • The specification is distinct from the code, and is all in one place (rather than being spread around the file). This makes it easy to read for other developers.

PS This is a in fact a cross platform post, despite looking like a .NET centric one. You can use this approach in any language.