As more test methods are added, the runtime may start throwing spurious errors. This is because the order of the tests may cause changes, and the ones that ran previously may modify the state of the workbench. This can be mitigated by moving the common setup and tear-down routines to a single place:
static
method beforeClass()
.@BeforeClass
from the org.junit
package.SWTWorkbenchBot
to the static
method, and save the value in a static
field.private static SWTWorkbenchBot bot; @BeforeClass public static void beforeClass() { bot = new SWTWorkbenchBot(); try { bot.viewByTitle("Welcome").close(); } catch (WidgetNotFoundException e) { // ignore } }
The JUnit annotation @BeforeClass
allows a single static
method to be executed prior to any of the tests running in the class. This is used to create an instance of SWTWorkbenchBot
, which is then used by all other tests in the class. This is also an opportune location to close the Welcome view, if it is shown, so that all other tests can assume that the window has been cleaned up.
Do not call bot.resetWorkbench()
, otherwise subsequent tests will fail in the test cases.