On the road to BDD… Or… to see the light

If you are a regular reader of this little blog in the middle of the internet, you might have realized that I am keen on “all things testing”. This is just a little experience report on my journey to better testing and getting everyone involved in the discussion about what we are building with our codez.

Figure: Everyone get together and collaborate

Story #1

On one of my projects in the past we happened to write a lot of tests that verify similar functionality that was very important for the business. It was so important that we as developers wanted to verify and check with the stakeholders and get a signature under the tests (signed with blood muahahaha).

Figure: Sign the tests, because they describe the system

To do so we needed to bring them in a format so they were easily readable. What I did then, was to write a T4 template that removed all C# noise and spit out a HTML file.

Figure: C# code gets converted to nicely formatted HTML code via T4

We (Devs and stakeholders) then sat together in front of a printed webpage and went through all scenarios. You can imagine the discussion and the help that this document provided.
Obviously every change on paper needed to be done by us devs in code.
It was very easy to regenerate the documentation… as you might think it is automated Winking smile 


Story #2

A couple of days ago I was doing a little Kata exercise (Tennis Kata) and thought to myself:
How would I write the test in Word or Notepad?

What I came up with was:

Simulate a TennisGame

Start new Game

P1 WinsBall
GameScore = 15:0

GameScore = 15:15

GameScore = 15:30

GameScore = 30:30

GameScore = 40:30

P1 Wins The Game

This is very easy to read and understand for everyone who is a little bit familiar with Tennis.

When I had this in Notepad I copied it into a C# test project and wrote helpers and extension methods around this in order to make it compile-able.

What I got then was

        public void Simulate_A_TennisGame()
            var tennisGame = StartNewGame();
            // Helpers
            var Game = tennisGame;
            var P1 = tennisGame.Player1;
            var P2 = tennisGame.Player1;






            P1.WinsTheGame();  // --> Game.Score.ShouldBe("P1");


I was quite happy with those extensions and helpers because they made all my tests very readable.


The result of both stories are nice readable tests that act as documentation with all the benefits of tests. 

What is next for me is to use one of these "fancy" BDD frameworks, where you write your tests in clear text format…

My lesson learned: Start to write your tests on paper or NotePad! And “grow” from there…


BTW: Here is a nice article about the “differences” between BDD vs ATDD

No comments:

Post a Comment

Latest Posts

Popular Posts