Mar 29 2008

FitNesse Workshop — source code and missing example

Published by gojko at 4:52 am under fitnesse, presentations

You can download the complete sourcecode for the examples from the SkillsMatter FitNesse workshop from here. Grab the related fitNesse tests from here. For a list of key ideas to take away from the session, click here.

Unfortunately, we did not have enough time to finish the example of integrating entity classes into FitNesse for .NET during the workshop. So here is the implementation:

Integrating FitNesse with Entity objects

Unlike value classes, where we can add a Parse method without any consequences, for entity classes the situation is not that simple. Entity objects cannot be easily “parsed” from a string, but there will typically be a way to find or create entities based on the description that will appear in FIT tables. Of course, the entity class, which is part of the business model, should not depend in any way on FIT classes. The dependency should work the other way round.

A solution that does not require any changes to the entity class code is to implement a cell handler for the entity type. Cell handlers tell FIT how to process the cells, and they are selected by cell text format and underlying object type. In this case, we just create a cell handler by extending AbstractCellHandler for the entity type and override the Parse method. That method should then execute the appropriate finder.

public class PlayerCellHandler : fitnesse.handlers.AbstractCellHandler
{

        public override bool Match(string searchString, Type type)
        {

            return typeof(Player).Equals(type);
        }
        public override object Parse(Fixture theFixture, Parse theCell,
           TypeAdapter theAdapter, object theTarget) {
            return Player.FindByName(theCell.Text);
        }
}

Unline the Parse method in the value class, the handler does not work automatically, it has to be activated using the CellHandlerLoader table (release 1.5 allows you to do this from a configuration file as well). If you want to use it in FitLibrary fixtures, then specify fitlibrary as the second argument to the load command. Here is how everything works together:

!|roulette3.PlayerStory|

!|CellHandlerLoader|
|load|roulette3.PlayerCellHandler|fitlibrary|

|Player|John|places|10|chips on|20|

|Player|Paul|places|20|chips on|11|

Add to Del.Icio.Us bookmarks

Trackback URI | Comments RSS

Leave a Reply