Mar 13 2006

Fitnesse Tutorial

admin @ 8:54 pm

Nancy & I went to Bob Martin’s Fitnesse tutorial this afternoon. OK… I went partly for Nancy’s benefit and partly to hear Bob speak.. and try to learn from him… afterall I help people use Fitnesse for pay. Anyway, it was excellent as expected. Nancy was really jazzed by Fitnesse. We really need to get it better supported for ruby and rails. That might be my next project.

Tags: 

Jan 12 2006

Singletons and FitNesse

admin @ 5:02 pm

FitNesse uses a single VM to run all pages in a test suite. This causes issues with static variables. They should be reset after each test page.

There are also issues with singletons. They, too, should be reset after each test page has run. So… you have to hunt down and reset each and every singleton in the system. As I was thinking about this, an approach occurred to me that will help with this, as well as making your singletons visible and easily findable.

Marking Singletons

I’ll start by making an interface to mark singletons:

public interface Singleton
{
}

Now I can mark each singeton, for example:

public class PrintQueue implements Singleton
{
    private static PrintQueue instance = null;

    public static PrintQueue getInstance () {
        if (instance == null) {
            instance = new PrintQueue();
        }
        return instance;
    }

    private PrintQueue() {
        //....
    }
}

So that makes the singletons easy to find.. just pull up implementors of Singleton.

Managing Singletons

Next I want to actively manage them. I’ll need to keep track of them:

public class SingletonManager
{
    private static List singletons = new ArrayList();

    public static void registerSingleton (Singleton aSingleton) {
        if (singletons.contains(aSingleton)) return;
        singletons.add(aSingleton);
    }
}

And I need to hook our singletons into the manager:

public class PrintQueue implements Singleton
{
    public static getInstance () {
        if (instance == null) {
            instance = new PrintQueue();
            SingletonManager.registerSingleton(instance);
        }
        return instance;
    }
}

Now I have a lists of all the singletons in the system. This lets me do interesting things.

Resetting Singletons

The first thing (maybe the only thing… and it’s enough… it’s the whole reason for this article) is to reset all the singletons.

public class SingletonManager
{
    public static void reset () {
        Iterator singetonIt = singetons.iterator();
        while (singletonIt.hasNext()) {
            Singleton aSingleton = (Singleton)singletonIt.next();
            aSingleton.reset();
        }
    }
}

Singleton needs a reset method now:

public interface Singleton
{
    void reset();
}

which needs to be implemented:

public class PrintQueue implements Singleton
{
    public void reset() {
        // do anything required to cleanup
        instance = null;
    }
}

Cleaning Up

Now I can use this reset facility from a fixture on the TearDown page on my test suites to reset all my singletons after each test page.

Of course, a better approach would be to not use singletons.

Tags: 

Jul 26 2005

Business Rules in Fit tutorial

admin @ 4:05 pm

I spent the afternoon in Rick Mugridge’s “Representing Business Rules in Fit” tutorial. Having a fair bit of experience with Fit, I did find it (as Rick had warned me) quite introductory.. but informational none the less. If you ever have the chance to hear someone speak about what they’ve “written the book on”.. do so. They always have something new & interesting to share. Rick is no exception. I picked up several nuggets .. mostly relating to FitLibrary.. the details of which were new to me. I got about half way through the Fit Book on the flight here.. and now I’m eager to finish it up. Based on conversations with Bob Martin and Rick, fit is just beginning.. there’s lots of interesting ideas floating around.

The last half of the tutorial was hands on (on paper) creating tests for some sample stories. We had a blast. Photos are here.

Tags: 

Jul 08 2005

Fit for Developing Software

admin @ 1:53 am

Fit for Developing Software: Framework for Integrated Tests by Rick Mugridge and Ward Cunningham

My copy of the new book by Ward Cunningham and Rick Mugridge arrived today. It looks fabulous. If you are using FIT or planning to.. GET THIS BOOK. I had the pleasure of reviewing an early version of the manuscript.. it was awesome.. but the final version looks even better.

I’m looking forward to reading it.. and i’ll be promoting it to anyone interested in using FIT.

Tags: