c#


After a day of getting FIT I was able to run the FitNesse wiki and poke around a bit and run some more acceptance tests.  This I found very interesting and quite impressive really.  It was truly simple.  So how do I write acceptance tests for my .NET applications.

The first step is understanding how a java based FitNesse wiki ran my .NET acceptance suites.  Fortunately this was pretty easy.  Under the fitnesse install directory their is a subdirectory called dotnet.  It the dotnet directory there is a .NET implementation of the FitServer that consumes test tables and communicates back results.  All we have to do in our wiki pages to tell FitNesse to use the .NET FitServer instead of the Java one to run our acception tests.  This is done by placing the following at the top of the wiki page that you write the acceptance test in:

!define COMMAND_PATTERN {%m %p}
!define TEST_RUNNER {dotnet\FitServer.exe}
!define PATH_SEPARATOR {;}
!path dotnet\*.dll

That’s it.  Then add the following test table to your page as well

!|eg.ArithmeticColumnFixture|
|x|y|plus()|
|10 |2 |12 |
|12 |3 |15 |
|100 |4 |104 |

The syntax is simple enough. 

  • Line 1:  The test fixture to run, with eg.ArithmeticColumnFixture being a fully qualified class name 
  • Line 2:  These are public members on the test fixture in first two columns, and the final column is the method that is called to perform the test.
  • Line 3-5: These values are assigned to the test fixture members and  the plus() called.

 

 

 

This page shows an example test table as it is rendered within the FitNesse.  Notice how FitNesse displays the .NET settings of the page.

To run the test, click the Test button that is in top left hand corner of the menu items.  (Note that to make a page a Test, select properties from the menu items and choose the Test option box.)

 

 

 

 

 

After you run the test, the results are displayed.

 

 

 

 

 

 

This works okay, now how do you write you own.  Take the following steps:

  • Open your VS Studio Project with the code that you want to test.
  • Write your acceptance test fixture code
  • Have your project *.dlls copied into the FitNesse/dotnet directory (Post Build Events in VStudio are good for this).
  • Write you test table wiki page and run.

 

One thing to note.  I was build using VS Studio 2005 and FitNesse was having problems finding classes within my assembly files.  To fix this I had to checkout the latest FitNesse.DotNet from the trunk and build it (You need NAnt). 

 

Once done, I copied the required binaries into the FitNesse\dotnet directory and everything worked fine.

One of the early things on a project to get sorted is who is going to be performing acceptance tests and how are they going to be written and executed? Just so we’re clear, acceptance tests are what the customer executes to verify what you (the team) have delivered is what they (the customer) asked for? If not, its back to the old drawing board.

FIT is a Framework for Integrated Tests that was created by Ward Cunningham and is gaining popularity. FIT simply consumes test tables, where a test table is a bunch of acceptance tests with input values and expected results. The trick is to provide test tables in tools that customers use as part of the every day life, and what is more everyday than Word and/or the Web.

Focusing on the Web side of things, FitNesse is a software testing tool that front ends FIT with a wiki. In Fitnesse the customer can write acceptance tests as simple tables that can be executed. These executable test tables call the software that you wish to be accepted by the customer.

Installing Fitnesse

Hmmm. This wasn’t so hard, simply do the following:

  • Download the latest zip and unpack into a directory of your choice.

At the time of writing, the latest zip was fitnesse20060719.zip. Note that FitNesse is a wiki implemented in java. However, it does support the running of acceptance tests for .NET. Now once unpacked, step into the root directory and issue the following:

  • run -p 8888

This will display a little text to say all is well. Now traverse to the FitNesse wiki at:

Here are a couple of quick links you should try:

The last one is very interesting because in the left hand menu, you’ll see the top menu item is Suite. Click this to run all the .NET acceptance tests. Note, that you need .NET installed on your Windows machine.

I’m tired. Tomorrow I’ll step through the problems I had trying to get my own acceptance tests running against inside Fitnesse.

One of the best ways to learn a new language for me is to write a load of tests that demonstrate how particular parts of the lanugage and/or platform work. For VisualStudio 2005, I wanted to do this without paying for the priviledge, so this ruled out:

  1. TestDriven.NET that is suppose to provide good test integration with VS.NET.
  2. Visual Studio Team Suite (VSTS) built in test framework. See what Charlie Poole, a member of NUnit team has to say about this.

So I installed NUnit and took the following steps within VisualStudio:

  1. Created a new VS Solution with a C# Library project called basics.
  2. Right clicked on the basics project and set the startup external program to be NUNIT_HOME/bin/nunit-gui.exe

Once done, everytime I run in debug it fires up the nunit gui and I can select my test and run it. I am now in a position to test and debug anything within the .NET platform that I can condense down into a simple test. Nice!

Again, that wasn’t so bad…

Learning the Microsoft Platform for me is like French.  You learnt it badly when you were young, stumbled by with it year in and year out, always promising yourself that one day you’ll do it properly!  For me, that day has come!

So I dusted off my First Edition of Eric Gunnerson’s (c) 2000 A Programmer’s Introduction to C# that was lying around on my bookshelf.  It’s not a great book, but a start.  4 hours later, armed with the syntactic basics of the C# language, I fire up my newly installed Visual Studio Professional.  I’m mildly excited.

The first thing I do in any new IDE is go to their equivalent of Tools | Options and step the enormous amount of configuration options, just see what’s there.  Here’s what I found interesting:

  • Environment | Help | Online - Over a slow connection, go standalone.
  • I tend to separate application from data on my desktop machines, so for me:
    • Change the default location for my Import and Exporting Settings
    • Change the default location for my vstudio projects and templates
  • Configuring the help system, msdn, C# formatting options and debugging.

Okay, I’m ready go.