2014-03-01 118 views
0

我无法理解即使消息正确,我的测试用例失败的原因。有没有人遇到过这个问题?它可以是正则表达式匹配吗?如果是这样,那么如何解决它?即使消息正确,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>/...)"

+2

测试代码请问? – fge

回答

2

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

@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); 
} 
+0

工作完美。谢谢! –