girlcoderuk











{August 5, 2012}   Agile BDD/TDD

Lots of people have a strange view about TDD/BDD programming methodology. People tend to write code then write a test for it, this usually doesn’t test fully the code as you are writing the test to match your code.

So for proper Agile Development we start with a test.

[Test]
public void i_should_be_able_to_instantiate_an_organisation()
{
    IOrganisation organisation = Substitute.For<IOrganisation>();
    organisation.IsInstanceOf<IOrganisation>();
}

At This point [Test] IOrganisation and Substitute.For<> are all underlined in red, So this is a failing Test,

So we use NuGet to add Nunit, NSubstitute and Chaining Assertions for Nunit, Then we use Resharper to Alt-Enter on IOrganisation to create a new Interface.

Running the tests now, Pass with a Green Bar.

So, We refactor, Test again and Save the output checking it into source control.

Why Refactor?

Well we want to move the newly created IOrganisation Interface to its own class, or even project.

Once this is done, we write another test.

[Test]
public void I_should_be_able_to_retrieve_the_number_of_salons_in_the_organisation()
{
    IOrganisation organisation = Substitute.For<IOrganisation>();
    organisation.GetSalonCount();
    organisation.Received().GetSalonCount();
}

This one forces the IOrganisation to have a GetSalonCount() method so we add it, then once Green Bar on the test, we Refactor if needed

then Save and check in.

TDD and Agile development means you can do many check ins to your repository per day, the reason is that we can roll back to any previous version easily and every checkin also is guaranteed to run as all test pass before a checkin.

Using this methodology we can write working software quickly knowing that all changes we do result in a passing test and nothing previously written has been broken,

Ron Jeffries has written a good book that covers this method of development, http://my.safaribooksonline.com/book/programming/csharp/0735619492 and I would recommend you try it if you can, and Safari Books online will provide access to it if you cannot find a paper version



Leave a comment

et cetera