I'm learning to use TestNG for IntelliJ IDEA 9.
As far as I understand, One way to put a test in a group called name
is to annotate it @Test(group = "name")
. To run a method before each test, annotate it with @BeforeMethod
.
In my test setup I want a method to run before each test only in a particular group. So there is a method beforeA
that runs before each test in group A
, a method beforeB
running before each B
test and so on.
Example code:
public class TestExample
{
@BeforeMethod(groups = "A")
public void beforeA()
{
System.out.println("before A");
}
@BeforeMethod(groups = "B")
public void beforeB()
{
System.out.println("before B");
}
@Test(groups = "A")
public void A1()
{
System.out.println("test A1");
}
@Test(groups = "A")
public void A2()
{
System.out.println("test A2");
}
@Test(groups = "B")
public void B1()
{
System.out.println("test B1");
}
@Test(groups = "B")
public void B2()
{
System.out.println("test B2");
}
}
I expect output like
before A
test A1
before A
test A2
before B
test B1
before B
test B2
but I get the following:
before A
before B
before A
before B
test A2
before A
before B
before A
before B
test B1
===============================================
test B2
===============================================
Custom suite
Total tests run: 4, Failures: 0, Skips: 0
===============================================
And IntelliJ IDEA has highlighted all my annotations with the message "Group A is undefined" or "Group B is undefined".
What am I doing wrong?