在无头环境中对SWT和Swing应用程序进行单元测试的最简单方法是? [英] Easiest way to unit test SWT and Swing apps in a headless environment?

查看:89
本文介绍了在无头环境中对SWT和Swing应用程序进行单元测试的最简单方法是?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为正在进行的项目对一些SWT和Swing代码进行单元测试,并且只要我从eclipse运行它们,测试就可以正常运行.

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.

一旦我在hudson环境中运行它们,它就会失败,因为hudson以无头模式运行了测试.

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

推荐答案

您可以运行 Xvfb (X虚拟帧缓冲,这是X11服务器,它在内存中执行所有图形操作),并且工作正常.

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

但是Hudson的Xvnc插件还有另一种解决方案.只需安装插件,然后在作业配置屏幕中选中复选框即可:

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

替代文本http://www.justinedelson.com/blog/wp-content/uploads/xvnc_box.jpg

然后,Hudson将自动启动Xvnc会话,并将DISPLAY环境变量设置为适当的值,然后在构建完成后关闭该会话.与Xvfb方法相比,它的一个优点是,如果同时有多个Swing/SWT项目构建,则每个构建都有自己的X会话.这可能根本不是问题,但似乎是个好主意.

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.

在使用此插件之前,您显然必须已安装Xvnc.不太明显(尽管很明智)的是,您还必须设置密码.您可以通过运行以下命令来做到这一点:

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

必须与Hudson运行的用户相同.

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

这篇关于在无头环境中对SWT和Swing应用程序进行单元测试的最简单方法是?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆