.net alternatives

by Michel Grootjans
posts - 49, comments - 84, trackbacks - 1

My Links

News

Shelfari: Book reviews on your book blog

Twitter












Archives

Post Categories

My first FitNesse test

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:

image

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:

image 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:

image 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.

Print | posted on Tuesday, November 25, 2008 10:39 PM | Filed Under [ .net FitNesse ]

Feedback

Gravatar

# re: My first FitNesse test

Hi,

I'm getting error after I put this line " !path C:\...\bin\Debug\*.dll"
at the top of the test.
I have a c#.net winform app for the calculator and it is located in "C:\Intellijet\WinFormTestFitness\WinFormTestFitness\bin\Debug"
and my exe is "WinformTestFitnesse.exe" so I have following code to generate my test :
!path C:\Intellijet\WinFormTestFitness\WinFormTestFitness\bin\Debug\*.dll
!|import|
|WinFormTestFitness|
!1 Let's run a simple calculator
!|CalculatorRunner|
|Arg1|Arg2|Sum?|
|0|0|0|

But when I hit "Save" button in (http://localhost:8080/DemoSuite.CalculatorTest) it gives me the following output with error :
classpath: C:\Intellijet\WinFormTestFitness\WinFormTestFitness\bin\Debug\*.dll

import
WinFormTestFitness

Let's run a simple calculator
CalculatorRunner
Arg1 Arg2 Sum?
0 0 0

Please help ...

10/28/2009 5:21 PM | IC
Gravatar

# re: My first FitNesse test

I'm not sure why you are getting that error. The example above states "!path C:\...\bin\Debug\*.dll" as an example. Don't take it literally. This should just be the path to the directory where your fixture assembly is located.

By the way, I recently gave up on absolute paths in fitnesse. I usually have a directory under the fitnesse root where I store the assemblies needed. So this !path directive now looks like this: !path /NameOfMyProject/*.dll
10/28/2009 9:39 PM | Michel Grootjans
Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification:
 

Powered by: