如何在 Jenkins CI 中集成 SWTBot 测试?

发布于 2024-12-05 17:55:39 字数 4496 浏览 0 评论 0原文

我有一个 SWT 应用程序(不是基于 Eclipse RCP),目前我使用 SWTBot 对其进行测试。从 Eclipse 运行测试时效果很好。我使用 ant 作为构建系统。

在 Jenkins 上,测试失败 - 抛出异常

[junit] Testcase: testPasswordChange(de.rssit.kgepc.swtbot.ChangePasswordTest): Caused an ERROR
    [junit] null
    [junit] java.lang.ExceptionInInitializerError
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeCharacter(Keyboard.java:100)
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Keyboard.java:89)
    [junit]     at org.eclipse.swtbot.swt.finder.widgets.SWTBotText.typeText(SWTBotText.java:92)
    [junit]     at org.eclipse.swtbot.swt.finder.widgets.SWTBotText.typeText(SWTBotText.java:78)
    [junit]     at de.foo.swtbot.pages.PasswordDialogPage.setText(PasswordDialogPage.java:70)
    [junit]     at de.foo.swtbot.pages.PasswordDialogPage.setOldPassword(PasswordDialogPage.java:30)
    [junit]     at de.foo.swtbot.ChangePasswordTest.testPasswordChange(ChangePasswordTest.java:43)
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getKeyboardLayout(KeyboardLayout.java:89)
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getDefaultKeyboardLayout(KeyboardLayout.java:75)
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.Keystrokes.<clinit>(Keystrokes.java:110)

搜索此特定问题没有产生任何有用的解决方案。

编辑:

添加 jvm 参数来设置美国英语可以修复此问题并运行一些测试;所有其他都带来以下堆栈跟踪:

[junit] Running foo.bar.swtbot.ChangePasswordTest
[junit] Testsuite: foo.bar.swtbot.ChangePasswordTest
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 1.453 sec
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 1.453 sec
[junit] 
[junit] Testcase: testPasswordChange(foo.bar.swtbot.ChangePasswordTest):    FAILED
[junit] null
[junit] junit.framework.AssertionFailedError: null
[junit]     at foo.bar.swtbot.ChangePasswordTest.testPasswordChange(ChangePasswordTest.java:46)
[junit] 
[junit] 
[junit] Cobertura: Loaded information on 219 classes.
[junit] Cobertura: Saved information on 219 classes.
[junit] Test foo.bar.swtbot.ChangePasswordTest FAILED
[junit] Running foo.bar.swtbot.LoginDialogTest
[junit] Testsuite: foo.bar.swtbot.LoginDialogTest
[junit] Exception in thread "UIThread" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4282)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4197)
[junit]     at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
[junit]     at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
[junit]     at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
[junit]     at foo.bar.swtbot.UIThread$1.run(UIThread.java:79)
[junit]     at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
[junit]     at foo.bar.swtbot.UIThread.startEventLoop(UIThread.java:74)
[junit]     at foo.bar.swtbot.UIThread.run(UIThread.java:59)
[junit] Caused by: org.eclipse.swt.SWTException: Widget is disposed
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4282)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4197)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4168)
[junit]     at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
[junit]     at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
[junit]     at org.eclipse.swt.widgets.Control.setVisible(Control.java:3725)
[junit]     at foo.bar.gui.Main.tryLogin(Main.java:142)
[junit]     at foo.bar.gui.Main.open(Main.java:117)
[junit]     at foo.bar.swtbot.AbstractMainTest$1.run(AbstractMainTest.java:46)
[junit]     at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
[junit]     at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
[junit]     ... 6 more
[junit] Exception in thread "Timer-0" org.eclipse.swt.SWTException: Widget is disposed
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4282)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4197)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4168)
[junit]     at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
[junit]     at org.eclipse.swt.widgets.Widget.getDisplay(Widget.java:582)
[junit]     at foo.bar.gui.AbstractKGEAdminDialog$1.run(AbstractKGEAdminDialog.java:46)
[junit]     at java.util.TimerThread.mainLoop(Timer.java:512)
[junit]     at java.util.TimerThread.run(Timer.java:462)

I've got a SWT application (not Eclipse RCP based) and I currently test it using SWTBot. This works fine while running the tests from Eclipse. I'm using ant as buildsystem.

On Jenkins the tests fail - an exception is thrown

[junit] Testcase: testPasswordChange(de.rssit.kgepc.swtbot.ChangePasswordTest): Caused an ERROR
    [junit] null
    [junit] java.lang.ExceptionInInitializerError
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeCharacter(Keyboard.java:100)
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.Keyboard.typeText(Keyboard.java:89)
    [junit]     at org.eclipse.swtbot.swt.finder.widgets.SWTBotText.typeText(SWTBotText.java:92)
    [junit]     at org.eclipse.swtbot.swt.finder.widgets.SWTBotText.typeText(SWTBotText.java:78)
    [junit]     at de.foo.swtbot.pages.PasswordDialogPage.setText(PasswordDialogPage.java:70)
    [junit]     at de.foo.swtbot.pages.PasswordDialogPage.setOldPassword(PasswordDialogPage.java:30)
    [junit]     at de.foo.swtbot.ChangePasswordTest.testPasswordChange(ChangePasswordTest.java:43)
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getKeyboardLayout(KeyboardLayout.java:89)
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.KeyboardLayout.getDefaultKeyboardLayout(KeyboardLayout.java:75)
    [junit]     at org.eclipse.swtbot.swt.finder.keyboard.Keystrokes.<clinit>(Keystrokes.java:110)

Searching for this specific problem did not result in any helpful solution.

Edit:

Adding the jvm args to set US english fixes this isse and makes some tests run; all other bring the following stacktrace:

[junit] Running foo.bar.swtbot.ChangePasswordTest
[junit] Testsuite: foo.bar.swtbot.ChangePasswordTest
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 1.453 sec
[junit] Tests run: 1, Failures: 1, Errors: 0, Time elapsed: 1.453 sec
[junit] 
[junit] Testcase: testPasswordChange(foo.bar.swtbot.ChangePasswordTest):    FAILED
[junit] null
[junit] junit.framework.AssertionFailedError: null
[junit]     at foo.bar.swtbot.ChangePasswordTest.testPasswordChange(ChangePasswordTest.java:46)
[junit] 
[junit] 
[junit] Cobertura: Loaded information on 219 classes.
[junit] Cobertura: Saved information on 219 classes.
[junit] Test foo.bar.swtbot.ChangePasswordTest FAILED
[junit] Running foo.bar.swtbot.LoginDialogTest
[junit] Testsuite: foo.bar.swtbot.LoginDialogTest
[junit] Exception in thread "UIThread" org.eclipse.swt.SWTException: Failed to execute runnable (org.eclipse.swt.SWTException: Widget is disposed)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4282)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4197)
[junit]     at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:138)
[junit]     at org.eclipse.swt.widgets.Display.runAsyncMessages(Display.java:4140)
[junit]     at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3757)
[junit]     at foo.bar.swtbot.UIThread$1.run(UIThread.java:79)
[junit]     at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
[junit]     at foo.bar.swtbot.UIThread.startEventLoop(UIThread.java:74)
[junit]     at foo.bar.swtbot.UIThread.run(UIThread.java:59)
[junit] Caused by: org.eclipse.swt.SWTException: Widget is disposed
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4282)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4197)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4168)
[junit]     at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
[junit]     at org.eclipse.swt.widgets.Widget.checkWidget(Widget.java:340)
[junit]     at org.eclipse.swt.widgets.Control.setVisible(Control.java:3725)
[junit]     at foo.bar.gui.Main.tryLogin(Main.java:142)
[junit]     at foo.bar.gui.Main.open(Main.java:117)
[junit]     at foo.bar.swtbot.AbstractMainTest$1.run(AbstractMainTest.java:46)
[junit]     at org.eclipse.swt.widgets.RunnableLock.run(RunnableLock.java:35)
[junit]     at org.eclipse.swt.widgets.Synchronizer.runAsyncMessages(Synchronizer.java:135)
[junit]     ... 6 more
[junit] Exception in thread "Timer-0" org.eclipse.swt.SWTException: Widget is disposed
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4282)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4197)
[junit]     at org.eclipse.swt.SWT.error(SWT.java:4168)
[junit]     at org.eclipse.swt.widgets.Widget.error(Widget.java:468)
[junit]     at org.eclipse.swt.widgets.Widget.getDisplay(Widget.java:582)
[junit]     at foo.bar.gui.AbstractKGEAdminDialog$1.run(AbstractKGEAdminDialog.java:46)
[junit]     at java.util.TimerThread.mainLoop(Timer.java:512)
[junit]     at java.util.TimerThread.run(Timer.java:462)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浅黛梨妆こ 2024-12-12 17:55:40

关于 java.lang.ExceptionInInitializerError

我注意到存在/已经存在与 DE_DE 语言环境缺少键盘布局相关的 Eclipse 错误。我可以建议您检查运行 junit 测试的进程的区域设置吗?如果将区域设置设置为 en_US,问题还会出现吗?

除了设置服务器进程的区域设置(例如 LC_ALL 环境变量?)之外,也许您可​​以在 junit 任务中使用显式区域设置,例如

<junit fork="yes">
  <jvmarg value="-Duser.language=en"/>
  <jvmarg value="-Duser.region=US"/>

关于 org.eclipse.swt.SWTException: Widget is Disposeed

也许是这样暴露了你的 UI 代码中的一个真正的错误,但我怀疑你需要查看你的单元测试。它们是无状态的,还是依赖于某种执行顺序才能可靠地工作?如果测试的执行顺序与您预期的不同,则可能会出现此错误。

Regarding java.lang.ExceptionInInitializerError

I notice that there are / have been Eclipse bugs relating to missing keyboard layout for DE_DE locale. Could I suggest you check the locale settings of the process running the junit tests. If you set the locale to en_US, does the problem still arise?

Apart from setting the locale for the server process (e.g. LC_ALL environment variable?), perhaps you could use explicit locale in your junit task, e.g.

<junit fork="yes">
  <jvmarg value="-Duser.language=en"/>
  <jvmarg value="-Duser.region=US"/>

Regarding org.eclipse.swt.SWTException: Widget is disposed

Maybe this is exposing a real bug in your UI code, but I suspect you need to look at your unit tests. Are they stateless, or do they depend on a certain execution order to work reliably? Perhaps this error can arise if the tests are executed in a different order than you expect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文