October 29, 2004

JUnit'isms!

Yesterday I came across an interesting phenomena with JUnit.

Consider the following piece of code from TestCase.java:

/**
 * Runs the bare test sequence.
 * @exception Throwable if any exception is thrown
 */
public void runBare() throws Throwable {
    setUp();
    try {
        runTest();
    }
    finally {
        tearDown();
    }
}

All seems quite good - we setUp() the test, run it, and tearDown() the test, even if the test throws an exception.

What happens though if setUp() throws an Exception? or there's a call to fail() inside of setUp()? Well, the test bails as it should with that Exception/error and you get a stack trace. The interesting thing however, is that tearDown() is not called.

Why can this a problem? Check the following:

public abstract class AbstractServerTestCase extends TestCase {
    protected void setUp() throws Exception {
        super.setUp();
        createServer();
    }
    protected void tearDown() throws Exception {
        destroyServer();
        super.tearDown();
    }
    private void createServer() { ... }
    private void destroyServer() { ... }
    // more code
}
public class ServerProtocolTestCase extends AbstractServerTestCase {
    protected void setUp() throws Exception {
        super.setUp();
        inputData = readResource("./data/input.bin");
    }
    private byte[] readResource(String location) {
        // some code that unfortunately throws an exception or calls fail();
    }
    private byte[] inputData;
    // more code
}

See the potential problem? The TestCase subclass throws an exception or fails(), causing JUnit to unwind it's execution and report the error, but the 'server' isn't shut down since it's in the tearDown() method. In your test cases are all running in the same VM, when the next test case runs, it will report something like a 'failed to bind' message, because it can't start up another server since the port is occupied.

Something to be aware of if you're using intermediate abstract classes to prime your test cases with data. :)

How did we resolve this? well, obviously setUp()'s should be working all the time (although we all know in reality this sometimes isn't the case), so we fixed this, but the main problem was that the failure of one test (the setUp() error), influenced the next one (with a bind or similar exception) when there wasn't something really wrong. To help us resolve this we added a guard to ensure that our server was shutdown even if a subclassed setUp() method threw an exception. Now, we're happy campers again :)

Posted by crafterm at 01:23 PM | Comments (3) | TrackBack

October 27, 2004

iPod Photo!

Has just been released... need I say more ;)

Update: engadget has some close up photos

Posted by crafterm at 09:08 AM | Comments (0) | TrackBack

October 14, 2004

Back in Frankfurt!

Arrived back in Frankfurt from the Cocoon GetTogether in Ghent last night with the guys. The trip was great, this was our third GetTogether and it keeps getting bigger and better every time. It was amazing to see how excited people were about Cocoon, even after sleep was removed from the agenda! :)

It was great to see those familiar faces again, the Outerthought, Luminus, S&N, Anyware Tech. guys and many others, it was also great to meet new people who were attending the GetTogether for the first time. Cocoon is still growing. I especially noticed a larger presence from the US this time around with people travelling from Chicago and San Fransisco amongst other places to attend.

The Ribbs restaurant was once again outstanding! as was the Pakhuis on GetTogether night. The social aspect of the Cocoon community is one of it's strongest properties, which could could be seen by all of the fun that went late into the evening (especially the late night joke telling sessions :) )

Guys, it was really great to see you all again and meet the new faces - looking forward to more real life events in the future! :)

Posted by crafterm at 10:18 AM | Comments (1) | TrackBack

October 12, 2004

More Cocoon GetTogether Talks!

gt7.png

After a 20 minute break Sylvain is now on stage talking about Cocoon Forms. CForms has seen a lot of growth and development recently, and is now one of the major benefits for using Cocoon.

Sylvain is presenting various solutions to complex real-world form management problems in webapps. In particular the <fd:union/> solution for multiple dynamic forms, and the recursive form solutions look really cool :)

Posted by crafterm at 11:57 AM | Comments (0) | TrackBack

Cocoon GetTogether away!

gt5.png

The Cocoon GetTogether is away! Steven has just finished the introductory talk, and Bertrand is now on stage presenting a solution to a Swiss Television website that was built with Cocoon - Nouvo.

Bertrand is also covering each aspect from developing a Cocoon based application, from sitemap to flowscript to business logic to database access. It's great to see a general overview of Cocoon presented so easily, as Cocoon can be a bit daunting when you first look at it - so, as Bertrand say's - it's not so complex after all :)

Posted by crafterm at 09:42 AM | Comments (0) | TrackBack

October 11, 2004

Cocoon Hackaton!

The Cocoon Hackaton is well underway, we've got perhaps 40-50 people here in the conference hall in Ghent, and there's been various breakout sessions that have occured. In particular the session about Cocoon Blocks was really interesting, with Pier, Ugo, and various others contributing to the new design of the Block management system behind Cocoon. Stefano even joined via video conference - right when we had the notebook projecting onto the wall (about 3m/3m!)

The Block management design sounds really cool - essentially the plan is to encapsulate each block within a classloader so that it can be primed with whatever statics are required to satisfy external library dependencies (ie. jaxp, logging, etc), and to expose proxied interfaces from the blocks to other blocks via an assembly system. This in turn will allow each block to be self-contained, and will allow the use of any arbitrary framework within the block for it's components (eg. Avalon, Spring, etc).

Certainly interesting stuff and will set us up well for the future. Part of the code is in Cocoon already in the form of Tani - the rest will be soon underway :)

Posted by crafterm at 04:17 PM | Comments (0) | TrackBack

Photos from Ghent!

A few photos from various places around Ghent, taken over the weekend. Quite a beautiful city :)

Posted by crafterm at 10:27 AM | Comments (0) | TrackBack

Arrived in Ghent!

ghent2004.png

Arrived in Ghent friday night for a brief weekend before the Cocoon GetTogether. The trip up from Frankfurt is really quick, only about 4 hours on the train which is nothing for an Australian :)

Spent the weekend visiting all different parts of the Ghent, also visited Steven on saturday which was great.

This is my third visit to Ghent and it's still breathtaking to see. More photos online soon :)

Posted by crafterm at 10:01 AM | Comments (0) | TrackBack