Bowling Game Kata Part One - Setup

The Bowling Game Kata was my first introduction to Test Driven Development. Uncle Bob wrote about it on his TheBowlingGameKata page.

I posted a presentation using MSTest on SlideShare. This walk-through will use NUnit.

Goal

Write a simple class that scores a game of bowling.

Iteration 0 - The Setup

You need Visual C# 2010 Express which can be installed for free through the Web Platform Installer.

Launch Visual Studio 2010. I will be using Visual Studio 2010 Professional for the screenshots.

File -> New -> Project

New Project Dialog

Choose a class library, name the project "BowlingGame", and click Ok.

Delete the Class1.cs file.

Before we write a line of production code, we want to have a failing test to cover it. You can use MSTest out of the box if you have Visual Studio 2010 Professional or above. In this example, I will be using NUnit inside of a class library. This allows the Express Editions of Visual Studio to perform test driven development.

Right-Click on the Solution -> Add -> New Project

Add Class Library

Choose a class library again, name the project "BowlingGame.Test", and click Ok.

After the project is created, rename Class1.cs to GameTest.cs. Game is the name of the class we will be testing, and Test is just a suffix that I like to add to the end of tests.

Remove the unused usings by right-clicking on the using statements and choose Organize Usings -> Remove and Sort. Now add the [TestFixture] attribute to the top.

BowlingGame.Test/GameTest.cs
namespace BowlingGame.Test
{
    [TestFixture]
    public class GameTest
    {
    }
}

Adding the TestFixture attribute causes a compile-time error. To fix it, we need to bring in the NUnit package using NuGet. Right-click on the BowlingGame.Test project and choose:
Manage NuGet Packages…

Search online for NUnit. Install it. You should now have references to the NUnit framework.

NUnit

Now you can add the using statement for the NUnit.Framework namespace. Just put your cursor over the TestFixture attribute and press CTRL+. (control + period). This will pull up the Generate from Usage menu. Choose the first option to add the using statement.

BowlingGame.Test/GameTest.cs
using NUnit.Framework;
            
namespace BowlingGame.Test
{
    [TestFixture]
    public class GameTest
    {
    }
}