在assertEquals()中使用正则表达式不起作用
我在assertEquals() 语句中使用正则表达式时遇到问题。这是声明。
Assert.assertEquals("regexp:*TST-*[0-9]{5}", driver.getTitle());
但我收到此错误:
org.junit.ComparisonFailure: expected:<[regexp:*TST-*[0-9]{5}]> but was:<[[#TST-23570] This is the new summary]>
看起来正则表达式只是一个正在比较的字符串。我缺少什么?
I'm having problems with using regexp in my assertEquals() statement. This is the statement.
Assert.assertEquals("regexp:*TST-*[0-9]{5}", driver.getTitle());
But I get this error:
org.junit.ComparisonFailure: expected:<[regexp:*TST-*[0-9]{5}]> but was:<[[#TST-23570] This is the new summary]>
It looks like the regexp is just a string that is being compared. What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看起来您实际上并没有使用正则表达式。看起来也许这就是你想要做的?
编辑#1:
您的正则表达式似乎也不太正确,请尝试:
It doesn't look like you're actually using the regex. It seems like maybe this is what you're trying to do?
EDIT #1:
It also seems like your regex might not be quite right, try:
您断言两个字符串是相同的。在您的情况下,您尝试检查您的标题是否等于“regexp:TST-[0-9]{5}”,而不是正则表达式。
您可能想要这样做:
http://cupi2.uniandes.edu.co/javadoc/j2se/1.5.0/docs/api/java/lang/String.html#matches(java.lang.String)
You're asserting the two Strings are the same. In your case you're trying to check that your title is equal to "regexp:TST-[0-9]{5}", and not the regexp.
You maybe want to do this:
http://cupi2.uniandes.edu.co/javadoc/j2se/1.5.0/docs/api/java/lang/String.html#matches(java.lang.String)