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.

Setting up Eclipse for Testing

So I started trying to figure out how to do Unit testing in Eclipse.
Eclipse defaults to JUnit 3 tests, but I want to use JUnit 4 tests. But the Eclipse JUnit 4 plugin is version 4.3 and I want to use 4.4. Then there is the difference between Assert.True and Assert.That, the latter requiring (or at least benefiting from) Hamcrest.
So I finally removed the Eclipse Junit 4.3 library from my BuildPath and added the junit-4.4.jar and hamcrest-all-1.1.jar instead.
In the process, I came across this Unit Testing in Eclipse page, which includes the fit.jar. Well, that launched me into another search as I tried to figure out how to run Fit tests in Eclipse. It turns out that Chengyao Deng wrote his masters thesis on this topic. That led me to the FitClipse Installation Instructions.
Well, my testing configuration wouldn’t be complete without jMock, so I found the jmocklipse site. No code present, just a good idea in Google’s suite of good ideas. Oh well, I can include the external jar manually.
So, now I have Junit, Hamcrest, Fit and jMock all set up and ready to test.
Now…if only I had something to test…

Further Reading:
FIT and Eclipse
Using JUnit with Eclipse IDE