In your case, you can simply call respective setUp method from respective Test method as you really don't have common @BeforeMethod
for each Test.
Or you can separate these two tests into different Test classes each having a @BeforeMethod
.
Or you can do conditional setup call based on test method name with one @BeforeMethod
method as below. Here @BeforeMethod
can declare a parameter of type java.lang.reflect.Method
. This parameter will receive the test method that will be called once this @BeforeMethod finishes
@BeforeMethod
public void setUp(Method method) {
if (method.getName().equals("testMethod")) {
setUp1();
} else if (method.getName().equals("anotherTestMethod")) {
setUp2();
}
}
public void setUp2() {
System.out.println("SetUp 2 is done");
}
public void setUp1() {
System.out.println("SetUp 1 is done");
}