Why would TestNG run an @AfterMethod method if the test didn't run? What
method would it run after?
On Thu, May 9, 2013 at 12:29 AM, Mircea Markus <mmarkus(a)redhat.com> wrote:
On 8 May 2013, at 20:46, Adrian Nistor wrote:
> @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?
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.:
@Test(groups="functional")
class NeverFailIntemittentlyTest {
CacgeManager cm;
@BeforeMethod
void setUp() {
cm = new EmbeddedCacheManager();
}
@AfterMethod (alwaysRun=true)
void tearDown() {
cm.stop();
}
}
If we run all the tests in the "xsite" profile, tearDown will throw NPE as
setUp is not invoked.
Writing tearDown like this should solve the problem:
@AfterMethod (alwaysRun=true)
void tearDown() {
if (cm != null) cm.stop();
}
Cheers,
--
Mircea Markus
Infinispan lead (
www.infinispan.org)
_______________________________________________
infinispan-dev mailing list
infinispan-dev(a)lists.jboss.org
https://lists.jboss.org/mailman/listinfo/infinispan-dev