Rapid Intro to using Slim with .Net
Thanks to Mike Stockdale for both writing the slim .Net implementation as well as helping me to get this working.
Get SliM.net
Note, this tool is called fitsharp, but it is actually an implementation of Slim for FitNesse. So while this title of this section does not patch the tool title, it better represents what the tool is.
- Download a release zip from jediwhale’s github account. Note, as of this update, the release version is called release.1.1.6.zip
- Extract the zip’s contents to some directory (I’ll use c:\tools\nslim)
- This creates a directory structure as follows:
Get FitNesse
title: FitNesse.Installing —
- Download FitNesse
- Place the downloaded zip file in some directory (hint, this next step creates a directory called FitNesseunder where you execute this command). For reference, I’ll be using ~/src/. The next step will create ~/src/FitNesse
- Execute the jar file once to get it extracted:
Note, this also attempts to start FitNesse on port 80. After this is done, you’ll either see an error message (if port 80 is in use):
Or you’ll see a message similar to this:
If you see the second option, kill FitNesse for now (hit ctrl-C).
Starting FitNesse
All of the tutorials assume you are running FitNesse on port 8080. These instructions show you how to start FitNesse on port 8080.
- Start a command prompt (shell)
- CD to your install directory and then go fitnesse directory created above
- Start FitNesse(Windows):
- Start FitNesse(Unix):
Update root page in FitNesse
Note, recent versions of FitNesse (after September 2009) do not require this step. The instructions will still work, there just won’t be any work for you. And as mentioned above, these steps assume you’re running FitNesse on your machine at port 8080, update the URL as necessary.
- Go to the following URL: http://localhost:8080/root
- Remove the following entries (if they are there)
In fact, it is safe to remove everything from the root page (and probably a good idea).
Create a page with necessary configuration
Note, if you are just using FitNesse for .Net, then you could put this information on the root page (that’s what I’d recommend in fact). For this example, I recommend using [[http://localhost:8080/FirstExample]].
- The first line overrides FitNesse’s default of executing tests using fit. Note that it is also possible to run in different VM’s with this command as well.
- The second line points to the Runner.exe created when you build slim.net. Update the directory as necessary.
- The third line defines how FitNesse calls the Runner.
Other than updating the directories, you can use this as is. It can be on a page by itself (e.g. on the root page or a page at the top of your test hierarchy).
Add references to your dll’s
- Use a !path statement to add each dll in your solution.
- You can optionally include the namespace using an import table (recommended):
Add a Test Table
Create a table. This is an example of a decision table taken from FitNesse itself. You can see the complete example at: http://localhost:8080/FitNesse.SliM.DecisionTable (of course update the URL as necessary).
Here’s the complete page
This is all of the above as a single page, which is what I actually did for this example:
Create the Fixture Code
Here’s the C# class that supports the “should I buy milk” decision table:
Note, the methods execute(), reset() and table(…) should be optional. Eventually they will be, but this is a early release of the Slim.Net implementation.
There are three “hook” methods you can also add:
Name | Description |
Execute() | Called once for each row, after setting all of the fields/attributes/properties (calling all of the setX methods). |
Reset() | Called once for each row, after completely processing the entire row. |
Table(…) | Called once for each table, before everything else. |
Here are example implementations for those methods:
Comments