title: TestNG annotations are not respected when run group based tests through command line
body: <p>I want to run my tests based on their groups through command line with Maven.(means if I say <code>mvn test -Dgroups=sanity</code>, only tests marked with <code>sanity</code> group will be run)</p>
  
  <p>For achieving above, I've following code in pom.xml. Because of following if nothing is provided on command line for group i.e <code>mvn test</code>, it will run tests with <code>regression</code> group</p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"&gt;
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
      &lt;groupId&gt;org.maven.test&lt;/groupId&gt;
      &lt;artifactId&gt;MavenTest&lt;/artifactId&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;properties&gt;
          &lt;groups&gt;regression&lt;/groups&gt;
      &lt;/properties&gt;
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
              &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
              &lt;version&gt;2.47.0&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.testng&lt;/groupId&gt;
              &lt;artifactId&gt;testng&lt;/artifactId&gt;
              &lt;version&gt;6.8.8&lt;/version&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
      &lt;build&gt;
          &lt;pluginManagement&gt;
              &lt;plugins&gt;
                  &lt;plugin&gt;
                      &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                      &lt;artifactId&gt;maven-surefire-plugin&lt;/artifactId&gt;
                      &lt;version&gt;2.18.1&lt;/version&gt;
                      &lt;configuration&gt;
                          &lt;groups&gt;${groups}&lt;/groups&gt;
                      &lt;/configuration&gt;
                  &lt;/plugin&gt;
              &lt;/plugins&gt;
          &lt;/pluginManagement&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>and my test class has <code>BeforeClass</code> and <code>AfterClass</code> annotations:</p>
  
  <pre><code>public class SanityTest {
    @Test(groups={"sanity"})
    public void f() {
      System.out.println("This is sanity test");
    }
  
    @BeforeClass
    public void beforeClass() {
      System.out.println("This is before class.");
    }
  
    @AfterClass
    public void afterClass() {
      System.out.println("This is after class.");
    }
  }
  </code></pre>
  
  <p>In order to run sanity tests, I hit <code>mvn test -Dgroups=sanity</code>. Sanity tests does run but <code>AfterClass</code>, <code>BeforeClass</code> methods are not executed.</p>
  
  <p>Its output is:</p>
  
  <pre><code>This is sanity test
  </code></pre>
  
  <p>actually, here I'm expecting:</p>
  
  <pre><code>This is before class.
  This is sanity test
  This is after class.
  </code></pre>
  
  <p>Could someone please help me what needs to be done so that TestNG annotations are also respected?</p>