title: How to ignore @BeforeMethod and @AfterMethod from testng results?
body: <p>Following is a <em>sample</em> test case created using <code>testng</code> framework,</p>
  
  <pre><code>public class MyTest {
  
      @BeforeMethod
      public void beforeMethod() {
      }
  
      @Test
      public void test1() {
      }
  
      @Test
      public void test2() {
      }
  
      @AfterMethod
      public void afterMethod() {
      }
  
  }
  </code></pre>
  
  <p>I am getting following <code>testng-results.xml</code> file,</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;testng-results skipped="0" failed="0" total="2" passed="2"&gt;
    &lt;reporter-output&gt;
    &lt;/reporter-output&gt;
    &lt;suite name="Surefire suite" duration-ms="15" started-at="2018-01-22T11:17:46Z" finished-at="2018-01-22T11:17:46Z"&gt;
      &lt;groups&gt;
      &lt;/groups&gt;
      &lt;test name="Surefire test" duration-ms="15" started-at="2018-01-22T11:17:46Z" finished-at="2018-01-22T11:17:46Z"&gt;
        &lt;class name="com.my.test.MyTest"&gt;
          &lt;test-method status="PASS" signature="beforeMethod()[pri:0, instance:com.my.test.MyTest@3567135c]" name="beforeMethod" is-config="true" duration-ms="4" started-at="2018-01-22T16:47:46Z" finished-at="2018-01-22T16:47:46Z"&gt;
            &lt;reporter-output&gt;
            &lt;/reporter-output&gt;
          &lt;/test-method&gt; &lt;!-- beforeMethod --&gt;
          &lt;test-method status="PASS" signature="test1()[pri:0, instance:com.my.test.MyTest@3567135c]" name="test1" duration-ms="0" started-at="2018-01-22T16:47:46Z" finished-at="2018-01-22T16:47:46Z"&gt;
            &lt;reporter-output&gt;
            &lt;/reporter-output&gt;
          &lt;/test-method&gt; &lt;!-- test1 --&gt;
          &lt;test-method status="PASS" signature="afterMethod()[pri:0, instance:com.my.test.MyTest@3567135c]" name="afterMethod" is-config="true" duration-ms="1" started-at="2018-01-22T16:47:46Z" finished-at="2018-01-22T16:47:46Z"&gt;
            &lt;reporter-output&gt;
            &lt;/reporter-output&gt;
          &lt;/test-method&gt; &lt;!-- afterMethod --&gt;
          &lt;test-method status="PASS" signature="test2()[pri:0, instance:com.my.test.MyTest@3567135c]" name="test2" duration-ms="0" started-at="2018-01-22T16:47:46Z" finished-at="2018-01-22T16:47:46Z"&gt;
            &lt;reporter-output&gt;
            &lt;/reporter-output&gt;
          &lt;/test-method&gt; &lt;!-- test2 --&gt;
          &lt;test-method status="PASS" signature="beforeMethod()[pri:0, instance:com.my.test.MyTest@3567135c]" name="beforeMethod" is-config="true" duration-ms="0" started-at="2018-01-22T16:47:46Z" finished-at="2018-01-22T16:47:46Z"&gt;
            &lt;reporter-output&gt;
            &lt;/reporter-output&gt;
          &lt;/test-method&gt; &lt;!-- beforeMethod --&gt;
          &lt;test-method status="PASS" signature="afterMethod()[pri:0, instance:com.my.test.MyTest@3567135c]" name="afterMethod" is-config="true" duration-ms="0" started-at="2018-01-22T16:47:46Z" finished-at="2018-01-22T16:47:46Z"&gt;
            &lt;reporter-output&gt;
            &lt;/reporter-output&gt;
          &lt;/test-method&gt; &lt;!-- afterMethod --&gt;
        &lt;/class&gt; &lt;!--com.my.test.MyTest --&gt;
      &lt;/test&gt; &lt;!-- Surefire test --&gt;
    &lt;/suite&gt; &lt;!-- Surefire suite --&gt;
  &lt;/testng-results&gt;
  </code></pre>
  
  <p>Notice that <code>afterMethod</code> and <code>beforeMethod</code> are also considered as test-methods. I want o ignore these methods from testng-result.xml as I am using this XML for further processing. </p>
  
  <p>I have following questions,</p>
  
  <ul>
  <li>Is there anyway to avoid <code>@BeforeMethod</code> and <code>@AfterMethod</code> methods in test result xml file? </li>
  <li>Is there anyway to differentiate between before and after methods from test-method XML tag? 
  (<em>i.e.</em> I can strictly name my methods to <code>beforeMethod_Ignore()</code> and <code>afterMethod_Ignore()</code> but it will be kind of hack instead of solution)</li>
  </ul>
  
  <p>I've gone through following links but couldn't find anything yet,</p>
  
  <ul>
  <li><a href="http://testng.org/doc/documentation-main.html#parameters-testng-xml" rel="nofollow noreferrer">http://testng.org/doc/documentation-main.html#parameters-testng-xml</a></li>
  <li><a href="http://www.seleniumeasy.com/testng-tutorials/include-exclude-test-methods-in-testng" rel="nofollow noreferrer">http://www.seleniumeasy.com/testng-tutorials/include-exclude-test-methods-in-testng</a></li>
  <li><a href="https://stackoverflow.com/questions/42242416/exclude-test-in-testng">Exclude Test in testNg</a> etc.</li>
  </ul>