开发者

In TestNG is there a way to run a cleanup method only after a particular test method?

开发者 https://www.devze.com 2023-01-04 13:33 出处:网络
One example: after a password change test executes I would like to a cleanup method t开发者_Go百科o reset the password back to the original password. Annotating the cleanup method with @AfterGroups an

One example: after a password change test executes I would like to a cleanup method t开发者_Go百科o reset the password back to the original password. Annotating the cleanup method with @AfterGroups and making the test method as the only method in a group is one way but it doesn't feel right.


This question might provide some help: TestNg, annotation "beforeTestMethod" and override. It's a very similar question, but with customizing the @BeforeMethod instead of the cleanup (@AfterMethod). Essentially, you could create a base test class, and have a child test class that contains all the methods requiring password reset, and which supplies it's own @AfterMethod. This may or may not be a logical choice in your situation, depending on your tests, of course.


Your suggestion is exactly how I would implement such a functionality, sorry it doesn't feel right to you :-)

How would you prefer to do this?

0

精彩评论

暂无评论...
验证码 换一张
取 消