Easiest way to unit test SWT and Swing apps in a headless environment?

Allain Lalonde picture Allain Lalonde · Oct 16, 2009 · Viewed 8.3k times · Source

I'm looking to unit test some SWT and Swing code for a project I'm working on and the tests run fine as long as I'm running them from eclipse.

As soon as I run them in my hudson environment it fails since hudson runs the tests in headless mode.

What's the best way of doing this? Open source solutions only please (since the project is open source).

Answer

Pascal Thivent picture Pascal Thivent · Oct 16, 2009

You could run Xvfb (X virtual framebuffer, an X11 server that performs all graphical operations in memory) and this works fine.

But there is another solution with Hudson's plugin for Xvnc. Simply install the plugin and check the checkbox in the job configuration screen:

alt text http://www.justinedelson.com/blog/wp-content/uploads/xvnc_box.jpg

Hudson will then automatically start up a Xvnc session and set the DISPLAY environment variable to the appropriate value and then shut down the session when the build is complete. One advantage this has over the Xvfb method is that if you have multiple Swing/SWT projects building simultaneously, each build has its own X session. This may not be an issue at all but it seems like a good idea.

Before using this plugin, you obviously have to have Xvnc installed. What's less obvious (although sensible) is that you must also set a password. You do this by running:

$ vncpassword

This has to be done as the same user Hudson runs as.