Categories
Development

Quicker JUnit Spring context tests in Maven

This is probably fairly well known, but I couldn’t find any doc on it when I searched so I’ll put it up here.

First off: Don’t load your Spring Context in your tests unless you absolutely have to. Some integration tests should load it, but keep it to a minimum. Loading the context is expensive, especially if you load up Hibernate and maybe H2 in that context.

Avoid loading the context is important both for speed and design. I have seen way too many tests where the context is loaded just because someone don’t want to do mocking. Besides, if you have to do a lot of mocking your design is usually too coupled, and should be changed.

So how can you speed up your tests in Maven?

Spring will cache the context and make sure it is only loaded once. But due to details I have not studied; in Maven, this only works for the tests that are in the same suite. It should work with fork=once on the surefire-plugin, but for some reason we need the suites too. Test which one works for you.

Drawbacks? If there is state in your context (database, stateful services) you will have created a dependency between your tests. That’s why, when it comes to database-testing you should use the AbstractTransactionalSpringContextTests which will automatically roll back your changes at the end of your tests. If state is modified in a way that has nothing to do with your database use setDirty() to signal to Spring that the context should be recreated for the next test. Of course then you get the time penalty of recreation.

Categories
Development

Jetty might become an Eclipse project

This post from Greg Wilkins suggests moving Jetty to the Eclipse foundation. There is a tiny risk that such a move would make everything more bureaucratic, but I think it will be a good decision if they decide to do it. It will increase the attention, and the Eclipse brand will make it a bit easier to swallow for operations or the finance guys.

Categories
Development

Smidig2008 videos online

Smidig2008 is the Norwegian agile conference. Completely organized by volunteers and excellent content. I was lucky enough to participate this year, but still have some talks I missed. I’ll be sure to check them out. You can find a list of best rated talks here.

You can see the entire list at: http://smidig2008.confreaks.com/ .