在 TestNG 中,有没有办法仅在特定测试方法之后运行清理方法?
一个例子:在执行密码更改测试后,我想要一种清理方法将密码重置回原始密码。用@AfterGroups注释清理方法并使测试方法成为组中唯一的方法是一种方法,但感觉不对。
One example: after a password change test executes I would like to a cleanup method to 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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题可能会提供一些帮助:TestNg,注释“beforeTestMethod”和覆盖。这是一个非常相似的问题,但是自定义 @BeforeMethod 而不是清理(@AfterMethod)。本质上,您可以创建一个基测试类,并拥有一个子测试类,其中包含所有需要密码重置的方法,并提供它自己的@AfterMethod。当然,根据您的情况,这可能是也可能不是一个合理的选择,具体取决于您的测试。
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?