Archive for Uncategorized

Making FitNesse Maven friendly (now with Slim)

Regular readers of my blog may remember that I’ve researched how to get the classpath from the FitNesse-process inherited by the Fit process that FitNesse spawns when it runs a test. This trick is an easy way to get around having to specify classpath variables in your FitNesse tests. This blogposts provides an easier way, plus compatibility with the new Slim testrunner in FitNesse.

This is the basic process:

  1. Create a Maven project with a dependency on your System Under Test in addition to FitNesse.
  2. Insert a few bootstrap files and classes into the project (to be explained)
  3. Start fitnesse.FitNesse as a main class in the project
  4. All classes in the project and its dependencies will now be available in Fixture classes

This article uses the 20081115 version of FitNesse, which is not yet in the Maven repository. To get it yourself, download it from the FitNesse website.

The problem

Fixing the classpath is exceedingly simple. But you need to understand a bit of the inner workings of FitNesse to get it to work. When you press the “test” button on a test, or the suite button on a test suite, FitNesse instantiates a class based on the registered “responder”. Our first order of business is to override this, but in order to do that, we need to take control over FitNesse.

You can do this by adding fitnesse.jar and fitlibrary.jar to your classpath, either manually in Eclipse, or by using a Maven dependency on org.fitnesse:fitnesse and org.fitnesse:fitlibrary.

Once FitNesse is in you IDE’s classpath, you can run the Java class “fitnesse.FitNesse”. This starts FitNesse on port 80. Navigate to, say “http://localhost/MyFirstTest”, and you’re ready to add a test.

In order to get it to work, though, you will have to do something like the following:


!path target/classes
!path /.m2/repository/org/fitnesse/fitnesse/20060719/fitnesse-20060719.jar
!path /.m2/repository/org/fitnesse/fitlibrary/20060719/fitlibrary-20060719.jar

!|my.test.ExampleFixture|
|first|second|sum?|product?|
|10|10|20|100|
|1|0|1|0|
|10000|1|10001|10000|

Ugh! Bad FitNesse!

The solution

What actually happens when you press “test” is that FitNesse creates and executes a Responder class. You can override a responder by adding a file called plugins.properties to the current working directory. Here is an example of such a file:


Responders = test:com.brodwall.fitnesse.InheritClasspathTestResponder

As you can see, I replace the test-responder with my own subclass. Here is the code of the InheritClasspathTestResponder for the very latest version of FitNesse:

public class InheritClasspathTestResponder extends TestResponder {
 
    private static final String PATH_SEPARATOR = System.getProperty("path.separator");
 
    /** For FitNesse 20081115 and later */
    @Override
    protected String buildClassPath() throws Exception {
        return super.buildClassPath() + PATH_SEPARATOR + getInheritedClassPath();
    }
 
    protected String getInheritedClassPath() {
        String inheritedClasspath = "";
        String parentClassPath = System.getProperty("java.class.path");
        String[] classPathElements = parentClassPath.split(PATH_SEPARATOR);
        for (String element : classPathElements) {
            inheritedClasspath += PATH_SEPARATOR + "\"" + element + "\"";
        }
        return inheritedClasspath;
    }
}

For older versions of FitNesse, you can instead override the buildCommand method as follows:

/** For FitNesse 20080812 and earlier */
protected String buildCommand(PageData data, String program,
                String classPath) throws Exception {
    return super.buildCommand(data, program, classPath + getInheritedClassPath());
}

This works both with both the original Fit test runner and the new Slim test runner. To try it out with a Slim runner, insert the following into a test page:


!define TEST_SYSTEM {slim}

(Notice that Uncle Bob’s article introducting Slim mistakenly !defines TEST_RUNNER. The correct variable is TEST_SYSTEM)

Debugging

In my original experiment, I also managed to get debugging support for FitNesse. This is how it works:

  1. After running a test, replace the part ?test in the URL with ?debug. The page will look like it’s hanging while the server is waiting for the debugger.
  2. In your IDE, attach a remote debugger to the Fit-process.
  3. You can now debug your code just as normal

This turned out to be a lot harder with the newest version of FitNesse. To support Slim, this version introduces the concept of TestSystem classes, of which there are two implementations, FitTestSystem and SlimTestSystem. These classes build up the (Java) command line to execute the test runner.

As of the current version of FitNesse, there is no plugin point to put new implementations of TestSystem, so I had to change TestResponder implementation of performExecution quite a bit. The original has some caching and other freaky stuff which I finally gave up trying to override. Sadly, my implementation only works for Slim. For some reason, overriding FitTestSystem#buildCommand causes FitNesse to hang. So: Use at your own risk.

To install the code, you have to modify the plugins.properties file described above:


Responders = test:com.brodwall.fitnesse.InheritClasspathTestResponder, \
debug:com.brodwall.fitnesse.DebugTestResponder

Here is the awful implementation of DebugTestResponder. I’ll see if I can get changes implemented in FitNesse to make it easier.

public class DebugTestResponder extends InheritClasspathTestResponder {
    private static final String PATH_SEPARATOR = System.getProperty("path.separator");
 
    private static final int DEBUG_PORT = 1044;
 
    @Override
    protected void performExecution() throws Exception {
        TestSystem testSystem = createTestSystem();
 
        // The following line is the correct behavior,
        //  but TestResponder.fastTest is private :-(
        //testSystem.setFastTest(fastTest);
        testSystem.setFastTest(false);
        testSystem.getExecutionLog(classPath, TestSystem.getTestRunner(data));
        testSystem.start();
 
        if (testSystem.isSuccessfullyStarted()) {
            addToResponse(HtmlUtil.getHtmlOfInheritedPage("PageHeader", page));
            SetupTeardownIncluder.includeInto(data, true);
            if (data.getContent().length() == 0)
                response.add(formatter.messageForBlankHtml());
            testSystem.sendPageData(data);
            testSystemGroup.bye();
        }
    }
 
    private TestSystem createTestSystem() throws Exception {
        String testSystemName = TestSystem.getTestSystemName(data);
        if ("slim".equalsIgnoreCase(TestSystem.getTestSystemType(testSystemName))) {
            return new SlimTestSystem(page, this) {
                @Override
                protected String buildCommand(String program, String classPath) throws Exception {
                    return DebugTestResponder.this.buildCommand(program, classPath);
                }
            };
        } else {
            // For some reason, overriding FitTestSystem.buildCommand causes FitNesse to hang
            return new FitTestSystem(context, page, this);
        }
    }
 
 
    protected String buildCommand(String program, String classPath) throws Exception {
        String debugOptions = "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address="
                        + DEBUG_PORT;
        return "java " + debugOptions + " " + "-cp " + classPath + PATH_SEPARATOR
                        + getInheritedClassPath() + " " + program;
    }
 
 
}

In conclusion

It is possibly, you could even say easy, to make Maven and FitNesse play nice. The trick with InheritClasspathTestResponder shows how you can stop maintaining the FitNesse classpath separate from the Maven classpath, which makes FitNesse into just another main-class in your system.

Sadly, the structure around the new TestSystem classes needs a little improvement to support debugging.

Comments (1)

I’m moderating the IfI alumni open source debate

The alumni organization from my old university is arranging a debate about open source, and I’ll be moderating. The debate will be next Wednesday at Scotsman in downtown Oslo.

There will be a four person panel, with two skeptics and two open source fans. So far, the panel looks as follows:

  • Heidi Arnesen Austlid, Friprogsenteret
  • Per Hove, Oracle Norge
  • Shahzad Rana, Questpoint
  • An exciting surprise!

The event will be held in The Scotsman, where they sell beer! And there will be free pizza! Free code, free beer, free pizza!

More information

Hope to see you there.

The text of this blogpost was shamelessly ripped of Ferris’s blog and patched slightly

Comments (2)

The Smidig 2008 conference is this week!

Smidig 2008, 9. - 10. oktober, Oslo Kongressenter

In the middle of changing jobs, I have also been quite busy with the last minute preparations for the Smidig 2008 conference for the Oslo Agile user community (“smidig” being the closest Norwegian translation of “agile”).

The conference be two days of lightning talks before lunch and open spaces after lunch. The program is in the final stages of being finalized as we speak.

There are still a few open seats. We’ve structured the price so that we don’t need to sell out to avoid losing money. But we want to make sure that as many people as possible take advantage of the opportunity to learn and discuss with a large number of other practitioners of agile software development.

You can sign up at http://smidig2008.no. Hope I see you there!

Comments (4)

Wordle

Here is a wordle of my blog:

(Inspired by Thomas Ferris)

Comments

I received an overwhelmingly warm welcome as the new chief scientist at Steria

I am changing employers. As of October 1st, I will no longer be lead software architect at BBS Nordic. Instead, I will be the chief scientist at the Norwegian division of Steria.

This weekend, I was invited to join my new employer at their gathering at a resort in the south of Norway. I’ve had a chance to speak with a lot of my new colleagues, and I was overwhelmed by the number of skilled, thoughtful and friendly people.

Steria has lots of very talented people, and I’m still looking for the best way to help the organization in my new role. I hope I can personally teach a lot of people the architecture and testing techniques that I’ve learned over the last years, and I hope I can help the people who actually produce the results that are needed at the end of the day get a stronger voice with our management and our customers.

Watch the thrilling story: What happens when you take a domesticated programmer out of his natural habitat and put him into a new world. Will be be overwhelmed by the differences, or will he be a new invasive species in the foreign ecosystem?

(Yes: I will insist that my proper title should still be JustAprogrammer. How long will I get away with it?)

Comments (4)

“Wow”-talks

I just watched another amazing talk from the TED conference. Spencer Wells is a natural public speaker. He talks about where we all, as a species, came from. Amazingly enough, everyone who is alive today share a common ancestor in Africa no more than about 2000 generations, or 60,000 years ago. Wells describes the fascinating questions and their answers, as we know them today.

The TED conference is full of remarkable talks. Here are some of my absolute favorites:

Read the rest of this entry »

Comments (1)

Ben Zander: Presentation with shining eyes

The TED conference has some amazing talks. If you never knew you were interested in car seats for children, classical music, or feet (yeah!), some of these talks will blow you mind.

A recent video that really moved me was Benjamin Zander, the conductor of the Boston Philharmonic. His insights and inspiration is invaluable for everyone who considers themselves a leader.

“The conductor doesn’t make a sound, he depends for his power on the ability to make other people powerful… I realized that my job was to awaken possibility in other people.”

Comments

Little Bobby Tables

I got this one from xkcd via Chris Searle. It’s now posted on the walls at work:

Oh, dear - did he break something?

Comments

Presenting Naked

My presentation at JavaZone was riddled with technical difficulties this year. To make a long story short: I learned five minutes before the presentation the the projector would be inoperative for a while (turned out to be 30 minutes). This threw a wrench into my plans, as I had planned to open with a demo.

I have read many times on presentation zen about presenting without slides. But before I stood in front of four hundred people with nothing to look at except me, I didn’t really believe how effective it would be. I’ve never seen a more attentive crowd! Thanks, everybody!

I don’t know if I had dared to throw the slides away if I hadn’t been forced to do so. But my next talk, I want to do without slides, too. This really was a serendipitous mishap.

There will be a video available of the talk, sadly, I forgot this, and spoke in Norwegian when I learned it was an all-Norwegian audience. I will link to the video for my Norwegian readers as soon as it is available.

Comments

Best Comment Overheard at JavaZone

“I just feel that in this company, there’s too many chiefs and not enough Indians.”

“Sure. Now, if they’d only been Indian chiefs.”

Read the rest of this entry »

Comments

Creative Commons Attribution 3.0 Unported
This work is licensed under a Creative Commons Attribution 3.0 Unported.