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

淺唱寂寞╮ 提交于 2019-12-03 05:28:44

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.

Try the Abbot Java GUI Testing Framework and SWTbot. At least SWTbot should be able to do it.

If neither offers a headless mode, then this blog post might give you some ideas how to get rid of the UI for testing.

Using Swing I tend to organise things so that the component tree can be created without a Window at the top. Doing this allows you to simply create a JPanel in a unit test and use that as your top-level component. There are certain things you cannot test, such as focus and any logic involved in the creation of the Frame for normal operation, but the vast majority can be tested.

You may want to look into the FEST library to make life easier whether you go headless or not, it looks very good: http://fest.easytesting.org/swing/wiki/pmwiki.php

I was sure I posted this here before, not sure what happened to it.

Cacio allows for running Swing app headless.

http://rkennke.wordpress.com/2011/10/17/cacio-for-ui-testing/

I don't know about SWT, but with Swing you can't. Any instantiation of a Window (JFrame, JDialog, etc.) even if it is never set to visible will blow up in headless mode (on JDK 5). What we did was not run in headless mode and install Xvfb to provide the windowing without actually having a real windowing system installed.

You could try RedDeer Testing framework https://github.com/jboss-reddeer/reddeer

• Support for running tests in a Jenkins CI environment (Hudson like)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!