title: why does TestNG execute @AfterMethod as a @Test if my first test is passed?
body: <p>why does TestNG execute @AfterMethod as a @Test if my first test is passed?</p>
  
  <p>For example the testoutput if my first test fails is:</p>
  
  <pre><code>1 test passed, 1 test failed.(3599,0 s)
      TestSuite FAILED
          run FAILED: check5=3 Expected: &lt;3&gt; got: &lt;5&gt;
          run passed (1.0s)
  </code></pre>
  
  <p>But if I just switch the order of test cases, so the first will pass, i get this:</p>
  
  <pre><code>3 test passed, 2 test failed.(2867,0 s)
      TestSuite FAILED
          run passed (1.0s)
          run FAILED: check5=3 Expected: &lt;3&gt; got: &lt;5&gt;
          AfterMethod FAILED (4,0 s) // &lt;--- wtf, this is not an @Test
          AfterTest passed (5,0 s)
          AfterSuite passed (15,0 s)
  </code></pre>
  
  <p>what is happening? my testngsuite.xml:</p>
  
  <pre><code>&lt;suite name="TestSuite_03"&gt;
      &lt;test name="TestCase_17"&gt;
          &lt;groups&gt;
              &lt;run&gt;&lt;include name="functest"/&gt;&lt;/run&gt;
          &lt;/groups&gt;
          &lt;classes&gt;
              &lt;class name="TestStep_003" desc="will pass" /&gt;
              &lt;class name="TestStep_012" desc="will fail" /&gt;
          &lt;/classes&gt; ...
  </code></pre>
  
  <p>I am using Maven, TestNG and Java via NetBeans</p>
  
  <p>my structure:</p>
  
  <pre><code>public abstract class TestCommon
  {
      @BeforeSuite(groups={"functest"})
      public void BeforeSuite()
      {
          // clean report folder
      }
      @BeforeTest(groups={"functest"})
      public void BeforeTest()
      {
          // start selenium browser
      }
      @AfterMethod(groups={"functest"}) // this is not a @test, still gets shown as failed
      public void AfterMethod()
      {
          // check for failure and capture screenshot
      }
      @AfterTest(groups={"functest})
      public void AfterTest()
      {
          // close browser
      }
  }
  
  
  public class TestStep_003 extends TestCommon
  {
      @Test(groups = {"functest"})
      public void run()
      {
          assertThat(5, Matchers.equalTo(5)); // will pass
      }
  }
  public class TestStep_012 extends TestCommon
  {
      @Test(groups = {"functest"})
      public void run()
      {
          assertThat(5, Matchers.equalTo(3)); // will fail
      }
  }
  </code></pre>
  
  <p>Annother issue is that the testoutput is not in order, the timestamps are
  not older -> newer, there are newer ones between old ones:
  thats how my output looks like:</p>
  
  <pre><code>1327840359762:  TestStep_012.AfterMethod // this is not the oldest timestamp!
  1327840359763:  TestStep_003.run 
  1327840359765:  TestStep_003.AfterMethod
  1327840357189:  TestStep_012.BeforeSuite
  1327840357192:  TestStep_012.BeforeTest
  1327840359758:  TestStep_012.run 
  1327840359762:  TestStep_012.AfterMethod
  1327840359763:  TestStep_003.run 
  1327840359765:  TestStep_003.AfterMethod 
  </code></pre>
  
  <p>furthermore, there are only 2 methods TestStep_003.run and and TestStep_012.run,
  and still it shows AfterMethod 4x</p>