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:
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.