Test

Running fitnesse from Eclipse

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;
    }
}
Advertisements

6 thoughts on “Running fitnesse from Eclipse

  1. Hi,
    Thanks a lot for the post. I’m able to launch Fitnesse by following the instructions. But on click of Test in TwoMinuteExample, I get below exceptions.

    Thanks in advance for the help.

    ————————————————————————-
    Exception in UI:
    ————————————————————————-
    TwoMinuteExample [add child]
    slim

    Date: 6:23:12 PM (IST) on Wednesday, October 12, 2011
    Test Page: .FitNesse.UserGuide.TwoMinuteExample
    Command: java -cp fitnesse.jar;fitnesse.jar;classes fitnesse.slim.SlimService 8086
    Exit code: 1
    Time elapsed: 102.547 seconds

    ——————————————————————————–
    Standard Error:

    java.lang.NoClassDefFoundError: fitnesse/slim/SlimService
    Caused by: java.lang.ClassNotFoundException: fitnesse.slim.SlimService
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    Could not find the main class: fitnesse.slim.SlimService. Program will exit.
    Exception in thread “main”

    ————————————————————————-
    In Console:
    ————————————————————————-
    java.lang.Exception: Test system not started
    at fitnesse.responders.run.MultipleTestsRunner.startTestSystemAndExecutePages(MultipleTestsRunner.java:109)
    at fitnesse.responders.run.MultipleTestsRunner.executePagesInTestSystem(MultipleTestsRunner.java:92)
    at fitnesse.responders.run.MultipleTestsRunner.internalExecuteTestPages(MultipleTestsRunner.java:83)
    at fitnesse.responders.run.MultipleTestsRunner.executeTestPages(MultipleTestsRunner.java:56)
    at fitnesse.responders.run.TestResponder.performExecution(TestResponder.java:141)
    at fitnesse.responders.run.TestResponder.doSending(TestResponder.java:45)
    at fitnesse.responders.ChunkingResponder.startSending(ChunkingResponder.java:67)
    at fitnesse.responders.ChunkingResponder.access$000(ChunkingResponder.java:17)
    at fitnesse.responders.ChunkingResponder$RespondingRunnable.run(ChunkingResponder.java:106)
    at java.lang.Thread.run(Thread.java:662)

  2. Thanks for the response. I added fitnesse.jar, fitlibrary.jar and my classes to !path and it worked.
    I can start fitnesse and run tests.

    But the debug doesn’t work! I’ve created a Fixture and have debug points in it. When I run the test, it runs through the program without stopping at debug point even though I’m starting FitnesseStarter.java in Debug mode and referring to the project’s classes from wiki (using !path)!

    Am I missing anything here?

    Thanks in advance.

  3. Can u Please give me the steps how to install and how to integrate fitnesse tool with eclipse ? We are mising steps some where ? Trying a lot since a week? can u pls help out?

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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