After my previous post, I've got a FitNesse server running and configured. It's now time to write some tests. Of course, since this is a demo, this will be a simple, self-explanatory test. I'll implement a simple calculator, capable of adding two integers.
Let's write that in FitNesse. First, I'll create a test suite called "DemoSuite". So I go to http://localhost:8888/DemoSuite. Since that page doesn't exist yet, FitNesse proposes a new page. I just accept it.
Then I go to a subpage, that I call http://localhost:8888/DemoSuite.CalculatorTest. Again, FitNesse doesn't recognize this page and proposes a new one. I now replace the content with this:
!1 Let's run a simple calculator
!|CalculatorRunner|
|Arg1|Arg2|Sum?|
|0|0|0|
This gets rendered like this:

Notice what is expressed here: The test is a CalculatorRunner, that's what the top of the column says. Then I provide two arguments: Arg1=0 and Arg2=0. The Sum of both arguments should be 0. How do I tell FitNesse that the Sum should be checked? Simple: I've appended a "?" after Sum. That's enough to tell FitNesse that this is an assertion.
This test won't run of course. We now need to create a test fixture to accept the test. These are the steps to follow:
- create a new project
- add a reference to "fit.dll", located in the dotnet2 directory in the fit directory
There we create a new class that has to match exactly the name of our test. That will be "CalculatorRunner"
using fit;
namespace MyBlogPosts.FitNesse
{
public class CalculatorRunner : ColumnFixture
{
public int Arg1 { get; set; }
public int Arg2 { get; set; }
public int Sum()
{
return Arg1 + Arg2;
}
}
}
Get it? Each column in the FitNesse test above matches a property or a method in my testclass.
Ok, if I now run the test, it will still fail! Why? Because it can't find the assembly it's in. Lets fix that, shall we. Hit "edit" on the testpage (or navigate to http://localhost:8888/DemoSuite.CalculatorTest?edit)
Add the following on top of the page:
!path C:\...\bin\Debug\*.dll
This will tell FitNesse to scan that directory for assemblies too. It's kinda like having a reference in a project.
On last thing before you hit "Save" (you hit it already, didn't you?). Add the following too:
!|import|
|MyBlogPosts.FitNesse|
This is the namespace to import during this test. Kind of a "using" declaration in C#. Now run the test. Did it work? For me, this is the result:
Looks OK to me. Lets expand the tests a little, shall we?
I'm editing the page like this:
!|CalculatorRunner|
|Arg1|Arg2|Sum?|
|0|0|0|
|1|1|3|
|-1|1|0|
|-100|1|-99|
Lets run it again:
Oops, looks like I missed one... but hey. That's exactly what tests are for, no?
By the way, this is what a ColumnFixture in FitNesse is. Three more testtypes coming up, plus a little refactoring.