If the test tries to access a property from the returned widget, there will be an exception thrown. For example, ctabs.get(0).getText()
will result in an Invalid thread access SWT error.
To perform testing on widgets, the code has to run in the UI thread. Either the Display.getDefault().syncExec()
or the equivalent Synchronizer
class can be used, but SWTBot has a UIThreadRunnable
that can launch code and a general interface called StringResult
, which is like a Runnable
that can return a String
value through syncExec
.
At the end of the
testTimeZone
method of theUITest
class, create a newStringResult
and pass it toUIThreadRunnable.syncExec()
.In the
run
method, get the firstCTabItem
and return its text value.After the
Runnable
method has run, assert that the value isAfrica
.The code looks like:
String tabText = UIThreadRunnable.syncExec(new StringResult() { @Override public String run() { return ctabs.get(0).getText(); } }); assertEquals...