title: TestNG BeforeMethod with groups
body: <p>I am wondering about <code>@BeforeMethod</code>'s usage with groups. In <a href="http://testng.org/javadoc/org/testng/annotations/BeforeMethod.html" rel="noreferrer">http://testng.org/javadoc/org/testng/annotations/BeforeMethod.html</a> it says:</p>
  
  <blockquote>
    <p>alwaysRun: If set to true, this configuration method will be run regardless of what groups it belongs to.</p>
  </blockquote>
  
  <p>So I have the following class:</p>
  
  <pre><code>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();
      }
  }
  }
  </code></pre>
  
  <p>Which outputs:</p>
  
  <pre><code>BeforeMethod G1
  BeforeMethod G2
  g1Test()
  BeforeMethod G1
  BeforeMethod G2
  g2Test()
  </code></pre>
  
  <p>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.</p>
  
  <p>I am using IntelliJ IDEA CE 10.5.2. I've run it with gradle 1.0-milestone-3, too.</p>