I believe that running fitnesse from inside of eclipse is a good idea. When Fitnesse is using my eclipse classpath I can modify my code without having to restart fitnesse. This gives me nice, short cycles and is major efficiency boost. A good colleague of mine, Morten Udnæs, had created a small start up class for Fitnesse in Eclipse. But when upgrading to the latest stable release of fitnesse (20090709) I found that I had to modify this class a bit – Uncle Bob has done quite a few refactorings over the last couple of releases.
The following code is tested against the 20090709 release of fitnesse. In the main method of the FitnesseStarter we first set up a FitnesseContext, which port to run fitnesse on and where the fitnesse tests reside (in our case in the folder src/test/fitnesse). The rootDirectoryName defaults to FitnesseRoot, in our case we have this structure so no need to set this.
The velocity engine is responsible for rendering data to html, we simply instantiate a velocity engine and tell where the template files are. Finally we set the eclipse path as class path on the jvm.
import org.apache.velocity.app.VelocityEngine;
import fitnesse.ComponentFactory;
import fitnesse.FitNesse;
import fitnesse.FitNesseContext;
import fitnesse.VelocityFactory;
import fitnesse.WikiPageFactory;
import fitnesse.responders.ResponderFactory;
public class FitnesseStarter {
public static void main(String args[]) throws Exception {
FitnesseStarter runFitnesse = new FitnesseStarter();
runFitnesse.start();
}
public void start() throws Exception {
FitNesseContext context = loadContext();
FitNesse fitnesse = new FitNesse(context);
fitnesse.applyUpdates();
boolean started = fitnesse.start();
if (started)
System.out.println(context);
}
protected FitNesseContext loadContext() throws Exception {
FitNesseContext context = new FitNesseContext();
context.port = 8090;
context.rootPath = "./src/test/fitnesse";
context.rootPagePath = context.rootPath + "/" + context.rootDirectoryName;
ComponentFactory componentFactory = new ComponentFactory(context.rootPath);
WikiPageFactory wikiPageFactory = new WikiPageFactory();
context.root = wikiPageFactory.makeRootPage(context.rootPath, context.rootDirectoryName, componentFactory);
context.responderFactory = new ResponderFactory(context.rootPagePath);
VelocityFactory.makeVelocityFactory(context);
VelocityEngine engine = new VelocityEngine();
engine.setProperty(VelocityEngine.FILE_RESOURCE_LOADER_PATH, "FitNesseRoot/files/templates");
VelocityFactory.setVelocityEngine(engine);
System.setProperty("eclipsepath", System.getProperty("java.class.path"));
return context;
}
}