I am wondering about @BeforeMethod
's usage with groups. In http://testng.org/javadoc/org/testng/annotations/BeforeMethod.html it says:
alwaysRun: If set to true, this configuration method will be run regardless of what groups it belongs to.
So I have the following class:
public class BeforeTest {
private static final Logger LOG = Logger.getLogger(BeforeTest.class);
@BeforeMethod(groups = {"g1"}, alwaysRun = false)
public void setUpG1(){
sleep();
LOG.info("BeforeMethod G1");
}
@Test(groups = {"g1"})
public void g1Test(){
sleep();
LOG.info("g1Test()");
}
@BeforeMethod(groups = {"g2"}, alwaysRun = false)
public void setUpG2(){
sleep();
LOG.info("BeforeMethod G2");
}
@Test(groups = {"g2"})
public void g2Test(){
sleep();
LOG.info("g2Test()");
}
private void sleep(){
try {
Thread.sleep(500);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
Which outputs:
BeforeMethod G1
BeforeMethod G2
g1Test()
BeforeMethod G1
BeforeMethod G2
g2Test()
Aside the fact that I think awaysRun is false by default, can anyone explain to me why both before methods are called before each test, disregarding the groups? Something like @Test(skipBeforeMethod = "setUpG1") would work too.
I am using IntelliJ IDEA CE 10.5.2. I've run it with gradle 1.0-milestone-3, too.