<div dir="ltr">Why would TestNG run an @AfterMethod method if the test didn't run? What method would it run after?<br></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Thu, May 9, 2013 at 12:29 AM, Mircea Markus <span dir="ltr"><<a href="mailto:mmarkus@redhat.com" target="_blank">mmarkus@redhat.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im"><br>
On 8 May 2013, at 20:46, Adrian Nistor wrote:<br>
<br>
> @BeforeMethod + alwaysRun=true is indeed pretty wrong and pointless in relation to groups but @AfterMethod + alwaysRun=true seems to make sense given this bit of javadoc: "If set to true, this configuration method will be run even if one or more methods invoked previously failed or was skipped". Does this imply our precious teardown method will be skipped because the test failed unless we add alwaysRun=true?<br>
</div>right, that's what I understand as well. Given that it might make sense to add alwaysRun to @AfterMethod as long as you expect it to be invoked in certain situations without the corresponding @BeforeMethod. The situation I'm talking about is when @BeforeMethod doesn't have "alwaysRun" and the owner class is in another test group, e.g.:<br>
<br>
<br>
@Test(groups="functional")<br>
class NeverFailIntemittentlyTest {<br>
<br>
CacgeManager cm;<br>
<br>
@BeforeMethod<br>
void setUp() {<br>
cm = new EmbeddedCacheManager();<br>
}<br>
<br>
<br>
@AfterMethod (alwaysRun=true)<br>
void tearDown() {<br>
cm.stop();<br>
}<br>
<br>
}<br>
<br>
If we run all the tests in the "xsite" profile, tearDown will throw NPE as setUp is not invoked.<br>
<br>
Writing tearDown like this should solve the problem:<br>
@AfterMethod (alwaysRun=true)<br>
void tearDown() {<br>
if (cm != null) cm.stop();<br>
<div class="im HOEnZb">}<br>
<br>
<br>
<br>
Cheers,<br>
--<br>
Mircea Markus<br>
Infinispan lead (<a href="http://www.infinispan.org" target="_blank">www.infinispan.org</a>)<br>
<br>
<br>
<br>
<br>
<br>
</div><div class="HOEnZb"><div class="h5">_______________________________________________<br>
infinispan-dev mailing list<br>
<a href="mailto:infinispan-dev@lists.jboss.org">infinispan-dev@lists.jboss.org</a><br>
<a href="https://lists.jboss.org/mailman/listinfo/infinispan-dev" target="_blank">https://lists.jboss.org/mailman/listinfo/infinispan-dev</a><br>
</div></div></blockquote></div><br></div>