[infinispan-dev] usage of alwaysRun=true on @BeforeMethod and alike

Dan Berindei dan.berindei at gmail.com
Thu May 9 03:02:29 EDT 2013


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 at 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 at lists.jboss.org
> https://lists.jboss.org/mailman/listinfo/infinispan-dev
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.jboss.org/pipermail/infinispan-dev/attachments/20130509/36b3abf9/attachment.html 


More information about the infinispan-dev mailing list