TestNG - 由意外异常生成错误

发布于 2024-12-09 07:58:34 字数 497 浏览 1 评论 0原文

我想知道,有没有办法设置 TestNG 来处理意外异常,例如错误,而不是失败?

我尝试在测试中抛出 RuntimeException,它被视为失败,而不是错误。 TestNG 文档仅讨论成功和失败状态 - http://testng.org/doc/documentation-main.html#success-failure

我希望在有关地址的第一个问题中具有与 JUnit 类似的 TestNG 行为 http://www.querycat.com/question/d1c9a200f18e6829cb06dda8eda8ad61

感谢您的帮助。

I would like to know, is there any way to set up TestNG to handle unexpected exceptions like errors and not like failures?

I tried to throw RuntimeException in my test and it was considered as failure, not like an error.
TestNG documentation talks only about success and failure states -
http://testng.org/doc/documentation-main.html#success-failure.

I would like to have TestNG behaviour similar to JUnit in first question on address
http://www.querycat.com/question/d1c9a200f18e6829cb06dda8eda8ad61

Thanks for your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

宫墨修音 2024-12-16 07:58:34

编辑:忽略我之前的内容。不幸的是,我相当确定你的问题的答案是否定的,TestNG 没有这个功能。完整的 TestNG 文档位于此处,因此如果某个功能未在其中列出页面可能不存在。请记住,尽管 TestNG 受到 JUnit 的启发,但它不应被视为 JUnit 功能的超集。如果您希望测试套件因异常而灾难性地失败,我唯一能想到的就是让它调用 System.exit(1)

Edit: Ignore what I had before. Unfortunately, I'm fairly certain the answer to your question is no, TestNG does not have this feature. The entirety of the TestNG documentation is here, so if a feature isn't listed on that page it probably doesn't exist. Remember that although TestNG is inspired by JUnit, it should not be considered a super-set of JUnit's features. The only thing I can think of if you want your test suite to catastrophically fail on an exception is to make it call System.exit(1).

困倦 2024-12-16 07:58:34

您使用了错误的异常。
JUnit 区分成功、失败(由assertXXX 抛出的AssertionException)和错误(所有其他非预期异常)。

如果您知道某个方法会抛出异常,您可以使用 @Test(expected=MyExpectedException) 捕获它。

You are using the wrong exception.
JUnit is distinguishing between success, failure (AssertionException thrown by assertXXX) and error (all other not expected exception).

If you know that a method will throw an exception you can catch it with @Test(expected=MyExpectedException).

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