【发布时间】:2017-09-12 10:31:02
【问题描述】:
expectedExceptionsMessageRegExp 正在尝试匹配 detailMessage 字段。我们可以匹配原因文本吗?即 Exception.getCause() 返回的文本? 这是因为 detailMessage 字段提供了非常通用的消息,如果预期消息与该文本匹配,它将超出测试用例的目的。
@Test(expectedExceptions = TestExecutionException.class, expectedExceptionsMessageRegExp = ".* HTTP 422.*")
public void test() throws Exception {
..
//some code that produces TestExecutionException with the cause HTTP 422
..
}
TestNG 错误是:
The exception was thrown with the wrong message: expected ".* HTTP 422.*" but got "Failed executing MessageExecutionTask"
at org.testng.internal.Invoker.handleInvocationResults(Invoker.java:1481)
at org.testng.internal.Invoker.invokeMethod(Invoker.java:754)
at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:901)
at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1231)
... 16 more
【问题讨论】:
标签: java testng http-error