Using "alwaysRun=true" in @AfterGroup annotation isn't possible

209 views
Skip to first unread message

lil...@my6sense.com

unread,
Mar 2, 2016, 10:52:57 AM3/2/16
to testng-users
Hi Guys,
I'm building an automation framework for my company and I've bumped into a serious obstacle.
I'm using groups in order to gather tests with mutual preparations and cleanup, and I was surprised to see that the @AfterGroup annotation will not run if a test in the group is skipped, or in other words, if the @BeforeGroup method failed.
Is there a specific reason that the annotation attribute "alwaysRun=true" will not work specifically for @AfterGroup annotation, but will work for all other annotations?
Is it possible to change it\work around it?
The current implementation of groups is not relevant for cleanup scenarios, but there is also no other solution in TestNG for cleanup that is not a suite\test level cleanup.
Please help me!!!  (-:
Lilach

Cédric Beust ♔

unread,
Mar 6, 2016, 10:35:43 AM3/6/16
to testng...@googlegroups.com

Configuration methods failing invalidates the run since all the bets are off when this happens.

Make sure your @BeforeGroups doesn’t fail (i.e. doesn’t throw, catch whatever might be thrown) and then you should see @AfterGroups being run.

-- 
Cédric


--
You received this message because you are subscribed to the Google Groups "testng-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to testng-users...@googlegroups.com.
To post to this group, send email to testng...@googlegroups.com.
Visit this group at https://groups.google.com/group/testng-users.
For more options, visit https://groups.google.com/d/optout.

lil...@my6sense.com

unread,
Mar 7, 2016, 4:44:44 AM3/7/16
to testng-users, ced...@beust.com
But that is exactly my problem: I want the @afterGroup to run when the @beforeGroup fails in order to perform cleanup and let the other tests run safely.
If I will put a "catch" clause in the @beforeGroup to prevent failure then the tests will run even though they are supposed to be skipped because their preparation failed, which is something I'm trying to avoid. Is there any way to force skipping a test via code? For example, force skipping a list of tests inside the @beforeGroups "catch" clause? 
Reply all
Reply to author
Forward
0 new messages