Question

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)
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top