3

我有一些最近失败的测试,原因如下:没有设置 X11 DISPLAY 变量,但是这个程序执行了一个需要它的操作。

这是完整的堆栈跟踪:

testGetDialog(simple.marauroa.application.core.IAddApplicationDialogProviderTest)  Time elapsed: 112 sec  <<< ERROR!
java.awt.HeadlessException: 
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
    at java.awt.GraphicsEnvironment.checkHeadless(GraphicsEnvironment.java:159)
    at java.awt.Window.<init>(Window.java:431)
    at java.awt.Frame.<init>(Frame.java:403)
    at java.awt.Frame.<init>(Frame.java:368)
    at javax.swing.SwingUtilities$SharedOwnerFrame.<init>(SwingUtilities.java:1733)
    at javax.swing.SwingUtilities.getSharedOwnerFrame(SwingUtilities.java:1810)
    at javax.swing.JDialog.<init>(JDialog.java:253)
    at javax.swing.JDialog.<init>(JDialog.java:187)
    at javax.swing.JDialog.<init>(JDialog.java:135)
    at simple.marauroa.application.core.IAddApplicationDialogProviderTest$IAddApplicationDialogProviderImpl.getDialog(IAddApplicationDialogProviderTest.java:97)
    at simple.marauroa.application.core.IAddApplicationDialogProviderTest.testGetDialog(IAddApplicationDialogProviderTest.java:49)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:68)
    at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:47)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:28)
    at org.junit.internal.runners.statements.RunAfters.evaluate(RunAfters.java:30)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.apache.maven.surefire.junit4.JUnit4Provider.execute(JUnit4Provider.java:252)
    at org.apache.maven.surefire.junit4.JUnit4Provider.executeTestSet(JUnit4Provider.java:141)
    at org.apache.maven.surefire.junit4.JUnit4Provider.invoke(JUnit4Provider.java:112)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.apache.maven.surefire.util.ReflectionUtils.invokeMethodWithArray(ReflectionUtils.java:189)
    at org.apache.maven.surefire.booter.ProviderFactory$ProviderProxy.invoke(ProviderFactory.java:165)
    at org.apache.maven.surefire.booter.ProviderFactory.invokeProvider(ProviderFactory.java:85)
    at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:115)
    at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:75)

在提到的代码行中就是这样:

return new JDialog();

我猜这与没有启用某些东西的 Jenkins 环境有关。如何解决这个问题?

我可以禁用该测试,但为什么要禁用呢?

4

2 回答 2

8

您需要使用 XVNC(或 XVFB)在虚拟(无头)图形环境中运行构建。请参阅wiki.cloudbees.com/bin/view/DEV/Testing+GUI+applications


编辑 20/01/2016:

上面的链接不再将您带到包含相关信息的页面。此链接显示当时的页面:https ://web.archive.org/web/20120717015714/http://wiki.cloudbees.com/bin/view/DEV/Testing+GUI+applications

于 2012-09-22T09:49:50.357 回答
2

您可能还考虑重构您的代码以使用模拟服务,以便测试不需要加载 AWT。这可能会使测试更快、更可靠,并最大限度地减少它们在 CI 服务器等新环境中失败的可能性。

于 2012-09-22T15:06:45.993 回答