Once more test methods are added, the runtime may start throwing spurious errors. This is because the order of the tests may cause changes, and ones that run previously may modify the state of the workbench. This can be mitigated by moving common setup and tear-down routines into a single place.
Create a
static
methodbeforeClass
.Add the annotation
@BeforeClass
from theorg.junit
package.Move references to creating a
SWTWorkbenchBot
to thestatic
method, and save the value in astatic
field.The code looks like:
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.