TestNG - 由意外异常生成错误
我想知道,有没有办法设置 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
编辑:忽略我之前的内容。不幸的是,我相当确定你的问题的答案是否定的,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)
.您使用了错误的异常。
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).