即使消息正确,TestNG测试也会失败并显示错误消息

时间:2014-03-01 12:21:24

标签: java exception message testng

我无法理解为什么即使消息正确,我的测试用例也会失败。有没有人遇到过这个问题?它可以是正则表达式匹配吗?如果是这样,那么如何解决它?

  

使用错误消息抛出异常:预期"'authority' Uri should have at least one segment in the path (i.e. https://<host>/<path>/...)"但获得了"'authority' Uri should have at least one segment in the path (i.e. https://<host>/<path>/...)"

1 个答案:

答案 0 :(得分:3)

是的,它需要一个正则表达式。你需要逃避括号(和点,但在这种情况下它没有什么区别)。以下测试通过:

@Test(expectedExceptions = RuntimeException.class,
      expectedExceptionsMessageRegExp = "'authority' Uri should have at least one segment in the path \\(i.e. https://<host>/<path>/...\\)")
public void test() {
    String input = "'authority' Uri should have at least one segment in the path (i.e. https://<host>/<path>/...)";
    throw new RuntimeException(input);
}