Tuesday, February 17, 2009

Extending the FitNesse ActionFixture



I've been working with FitNesse lately. I find it to be relatively simple to use, although I have admittedly not gone beyond that basics as of yet. The install was simple and the ColumnFixture is  very straight-forward. I had a number of tests up and running in a matter of hours.

But I had some minor issues with the ActionFixture. I used the sample code that came with FitNesse to get me started:

public class CountFixture extends Fixture {
  private in counter = 0;

  public void count() {
    counter++;
  }

  public in counter() {
    return counter;
  }
}

The table is as follows:

|!- ActionFixture -!|
| start | !- Customer Action Fixture -! |
| check | counter | 0 |
| press | count |
| check | counter | 1 |
| enter | counter | 5 |
| press | count |
| check | counter | 6 |



Everything is fine except I get an error on the enter. Method not found. So what gives? This is the EXACT code provided by FitNesse.

I tried the obvious things like making the counter public as is done with ColumnFixtures, but to no avail. I did some digging around and some experimenting and I finally decided to try adding another method to the class. One that accepts a parameter and updates our private global counter variable. The final class is as follows:

public class CustomerActionFixture extends Fixture {
  private int counter = 0;

  public void count() {
    counter++;
  }

  public void counter(int i) {
    counter = i;
  }

  public int counter() {
    return counter;
  }
}

And now, all is well. Hopefully this will save some of you a little pain.

0 comments: