我有一个 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 args 来设置美国英语修复了这个问题并使一些测试运行;所有其他带来以下堆栈跟踪:
[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)