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:
Create a
static
methodbeforeClass()
.Add the annotation
@BeforeClass
from theorg.junit
package.Move references to create a
SWTWorkbenchBot
to thestatic
method, and save the value in astatic
field.The code looks like this:
private static SWTWorkbenchBot bot; @BeforeClass public static void beforeClass() { bot = new SWTWorkbenchBot(); try { bot.viewByTitle("Welcome").close(); } catch (WidgetNotFoundException e) { // ignore } }
Run the tests and ensure that they pass appropriately.