Run UI tests in the background on Linux

When you run JUnit tests that open windows and dialogs, all these windows pop up on your screen like fireworks, making your desktop unusable for minutes.

If you’re lucky enough to work on Linux, there’s an easy way to get rid of all the flickering. You can simply redirect your UI tests onto a virtual screen. I was surprised how easy that is and thought it’s worth sharing.

All you need is the X virtual framebuffer (Xvfb). Install this tool if you don’t have it yet, e.g. on a Debian-based system, you’d type:

$ sudo apt-get install xvfb

Then start a virtual display with a number of your choice, but greater than zero (I use 99). You can either do that manually:

$ Xvfb :99 &

or automatically at system startup using an init script like this one. There are some command line options to adjust the dimensions and color depth of the virtual screen, but I’m fine with the defaults.

Now you can run your tests with the environment variable DISPLAY set to :99. In Eclipse, you can do this in the Environment tab of your launch configuration:

PluginTestOnVirtualDisplay Run UI tests in the background on Linux

When running a Maven build from the command line, you can simply export this variable before you start maven.

$ export DISPLAY=:99
$ mvn clean install

That’s it. Now your UI test suite runs quietly in the background and let’s you keep working.

I couldn’t find anything similar for Windows or Mac, if you know how to do it, I’m interested to hear about it.

3 Responses to “Run UI tests in the background on Linux”

  1. Andrew Eidsness says:

    That is a great idea, I can’t believe I never thought of it. Thanks for posting!

  2. Lorenzo says:

    A similar procedure is detailed on swtbot wiki, but for that kind of tests you also need a window manager as far as I know, and xephyr.

    And of course Linux rocks :-)

3 responses so far

Written by . Published in Categories: Planet Eclipse

Author:
Published:
Dec 6th, 2013
Follow:

Twitter Google+ GitHub