views:

19

answers:

1

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?

+1  A: 
  1. The listing isn't in good order, this is intelliJ's fault. Run the test in command line or with maven the order will be correct.
  2. @BeforeMethod and @AfterMethod seem broken with groups.
  3. IntelliJ remember groups you used before, if you use a group that isn't remembered yet, the message "Group X is undefined" will be shown. Just pres alt + Enter on an undefined group to remember it.

Resources :

Colin Hebert
Do you know of any workaround for now? Just now I'm doing without groups, which is introducing some redundancy.
isme
No, I didn't find one.
Colin Hebert