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 new chessboard
    var chessBoard = new ChessGame(layout);        
    //And a pawn with an enemy piece in an adjacent diagonal square
    chessboard.Move("d2 d4");
    chessboard.Move("e7 e5");

    //When the pawn's moves are listed
    var moves = chessBoard["d4"].Piece.PotentialMoves();            
    //Then the enemy pieces square is available as a move
    Assert.True(moves.Select(move => move.Dest).Contains(chessBoard["e5"]));

The comments specify the behaviour of the system, the code implements it. Refactoring the code will not obscure the meaning of the test, nor mess around with the Arrange/Act/Assert layout. It's easy peasy to write, and easy peasy for someone else to come along and understand it.

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.