In order to verify that everything works correctly, let's write a quick test. To make the first example as simple as possible, we will not test a business object but the string concatenation operator. To test whether it works, we will join the words “Hello” and “World”, put a blank in between, and check that the result is “Hello World”. In the process, we write a simple test page in FitNesse, bind that test page to .NET code and make FitNesse run .NET tests. We will first create and run this test example very quickly, but then go back and work through the details.
FIT is the engine driving FitNesse, responsible for executing tests. It reads HTML files, looks for tables, and uses data in the tables to execute tests and compare results to expectations. FitNesse is a wiki[4] site with helpful mark-up shortcuts, designed to help with building the test pages.
FIT requires a thin integration layer on top of our code,
which provides hooks to the methods and properties of business
objects so that they can be mapped to test data and expected results.
This integration layer typically consists of a set of classes derived from
fit.Fixture, or some of its standard
subclasses.
Open a new .NET project, and copy this class into it (without the line numbers):
1 namespace HelloWorld
2 {
3 public class OurFirstTest : fit.ColumnFixture
4 {
5 public string string1;
6 public string string2;
7 public string Concatenate()
8 {
9 return string1 + " " + string2;
10 }
11 }
12 }
Add a reference to
fit.dll
and fitsharp.dll
(in the dotnet2
FitNesse folder) to your project and compile it.
Now open http://localhost:8888/HelloWorld in your browser. Because HelloWorld page does not yet exist, FitNesse opens the page editor: a big text box with several buttons. Now type the following code into the text box (without the line numbers) and click Save. Make sure to replace the DLL path with the full path to your project's DLL. Note that there is a comma between FitServer and dotnet2, the other separators are dots.
1 !define COMMAND_PATTERN {%m -r fitnesse.fitserver.FitServer,dotnet2\fit.dll %p}
2 !define TEST_RUNNER {dotnet2\Runner.exe}
3 !path D:\work\fitnesse\HelloWorld\bin\Release\HelloWorld.dll
4
5 !|HelloWorld.OurFirstTest|
6 |string1|string2|Concatenate?|
7 |Hello|World|Hello World|
FitNesse now creates a new page and displays it (Figure 2.2, “FitNesse creates a new page for the Hello World test”). Next, you have to tell FitNesse that this is a test page — click Properties on the left, select the Test radio-button (Figure 2.3, “Remember to mark the page as a test”), and click Save Properties. Page properties define what the user can do with the page — more precisely, which buttons will be offered in the left-hand menu.
When the page reloads, you will notice a new button on the left: Test. Click it to make FitNesse run the test. You should see a page similar to Figure 2.4, “Our first test passed!”, telling you that the test passed.
OK, that was our first FitNesse test in .NET, and it passed. Hurrah! Now let's go a few steps back and see what really happened.
[4] A web-based content management system, typically intended for collaborative use, allowing people to create and edit pages easily using a simple mark-up syntax. Wikipedia is a popular example, which you have almost certainly seen by now, so working with FitNesse should not feel strange.





![[Tip]](../images/resources/tip.png)


