在 TestNG 中,有没有办法仅在特定测试方法之后运行清理方法?

发布于 2024-09-07 08:18:34 字数 89 浏览 1 评论 0原文

一个例子:在执行密码更改测试后,我想要一种清理方法将密码重置回原始密码。用@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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

素食主义者 2024-09-14 08:18:34

这个问题可能会提供一些帮助: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.

一身仙ぐ女味 2024-09-14 08:18:34

您的建议正是我将如何实现这样的功能,抱歉,您感觉不合适:-)

您希望如何执行此操作?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文