How to Run JavaFX in Headless mode for Testing

Richard Bair richard.bair at
Thu Jan 24 08:48:15 PST 2013

Do you mean just running any old unit tests, or visual based unit tests?

For visual based unit tests, we have no such mechanism, but need it ourselves. To this point all our headful GUI testing has been happening on machines configured to run in headful mode, but our continuous build / test servers are all headless and that limits which tests we can run there.

Just about a year go exactly I started writing a headless implementation of Glass which used Java2D for rendering to a buffered image and "faked out" other operating system services such as an event queue. But it was more of an experiment and get-to-know Glass, as much as I would have liked the time to finish it out, I just didn't have it.

Since then, the embedded guys have integrated into our repo, including a potential solution called "Lens", which is a Glass implementation mostly in Java and meant to run on embedded devices with limited OS support (including no desktop environment), and so implements most things itself with some limited native code. I have not inspected it myself so I don't know how feasible it is for this particular issue.

In addition there is the issue of how to handle multi-platform headless tests. Do you want to run the visual tests including the OpenGL or D3D pipeline, or is a software pipeline good enough?

For non-visual unit tests, we've not had a problem. Generally I will create a Node and just test its state, but if I need to make sure layout etc has happened or CSS is working I do something like:

    @Test public void fontSetFromCSS() {
        textInput.setStyle("-fx-font: 24 Helvetica");
        Scene s = new Scene(textInput);
        assertEquals(Font.font("Helvetica", 24), textInput.getFont());


On Jan 23, 2013, at 11:24 PM, Peter Pilgrim <peter.pilgrim at> wrote:

> Hi All
> How do we run JavaFX 8 / JavaFX 2 in headless mode for unit test?
> Is there a secret GUI flag? e.g. java -Djava.awt.headless=true
> Should we install a virtual X frame buffer?
> Of course, JavaFX is bypassing AWT in its architecture; so none above,
> I think, are guaranteed to work
> -- 
> Peter Pilgrim,
> **Java Champion**,
> Java EE Software Development / Design / Architect for `BlueChip'
> enterprises, London, UK
> JavaFX ++ Scala ++ Groovy ++  Android ++ Java
> ::  ::
> :: ::
> ::  ::
> :: Skype Call peter_pilgrim ::
> :: ::

More information about the openjfx-dev mailing list