title: IntelliJ IDEA + TestNG: Run a method before each test in a group
body: <p>I'm learning to use TestNG for IntelliJ IDEA 9.</p>
  
  <p>As far as I understand, One way to put a test in a group called <code>name</code> is to annotate it <code>@Test(group = "name")</code>. To run a method before each test, annotate it with <code>@BeforeMethod</code>.</p>
  
  <p>In my test setup I want a method to run before each test only in a particular group. So there is a method <code>beforeA</code> that runs before each test in group <code>A</code>, a method <code>beforeB</code> running before each <code>B</code> test and so on.</p>
  
  <p>Example code:</p>
  
  <pre><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");
      }
  }
  </code></pre>
  
  <p>I expect output like</p>
  
  <pre><code>before A
  test A1
  before A
  test A2
  before B
  test B1
  before B
  test B2
  </code></pre>
  
  <p>but I get the following:</p>
  
  <pre><code>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
  ===============================================
  </code></pre>
  
  <p>And IntelliJ IDEA has highlighted all my annotations with the message "Group A is undefined" or "Group B is undefined".</p>
  
  <p>What am I doing wrong?</p>