Fit Testing 101

Well, I finally got the Fitnesse server running and configured my first tests.  (Their site is down, but the Fitnesse jar’s were available here, and the zip was available on sourceforge.)  I run on Windows Vista, use Eclipse Europa as my IDE and Maven2 for the builds, so it was a bit of an ordeal to configure. Here’s what I ended up with.
My dev project is in standard Maven folders:
so I added:
(I’m quite sure that’s a naming violation of some sort, but it works for now. I can refactor it later when I find out what it should have been called.)

In my Eclipse project, I created this java class:
public class FitTestBasicTest extends ColumnFixture {
  public double quantity, price;
  public double extendedprice() {
    return quantity * price;

I had to change the Maven pom to include the new test\fitnesse folder. So I used the build-helper-maven-plugin

Now, whenever I run mvn test, it will compile the Fit tests as well as the JUnit tests.

Meanwhile, I unzipped the Fitnesse server and edited the run.bat file so that Fitnesse uses port 8083 instead of 80 because I already have a TON of web servers running on my dev box.  I just changed the java line to include the port parameter, like this:
java -cp fitnesse.jar fitnesse.FitNesse -p 8083 %1 %2 %3 %4 %5

So, with the Fitnesse Wiki running, I connected to http://localhost:8083/.
Following the Fitnesse model in their Acceptance Tests, I created a MyTests.SuiteAcceptanceTests page. It took a lot of fiddling to figure out what the Classpaths should be and how to get Fitnesse to find the test Fixture itself, but this works:
!2 ''!-My-! Acceptance Tests Suites''
|^SuiteTests|''Test Various Acceptance Scenarios.''|
!2 ''Classpaths''
!path C:\workspace\trunk\target\test-classes\
!path C:\workspace\trunk\target\classes\
!2 ''Fixtures''
!fixture com.myapp.fitnesse.fixtures.firsttests.FitTestBasicTest

Naming the fixture in the Suite’s page allows the -Insert Fixture Table – combo at the bottom of the page editor to insert a table from the class definition in the test fixture.  I also created a MyTests.SuiteAcceptanceTests.SuiteTests.SetUp page to handle the namespace import:

Lastly, I created the MyTests.SuiteAcceptanceTests.SuiteTests. MyFirstTest page.
I selected the Insert Fixture Table combo and picked the FitTestBasicTest class. Fitnesse inserted the table so I added some values. It turned out I needed to delete the line from the table that shows the types.
|10 |20 |200 |

So, the code compiles, the unit tests run and pass, the fit tests run and pass. Now, to mavenize the whole process again and get the maven fitness plugin working so the tests are run automatically.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s