Junit:我如何使用断言来检查 String > 0
我有一个字符串,我想检查该字符串是否 > 0 使用断言
尝试: 使用assertFalse我无法设置2个字符串:我的值和“0”。
还有另一种说法吗:assertThat "myString"> “0”?
我的目的:
myTable.getValue =>this return a string : "20"
I would like to check that this string is > or different from "0"
谢谢
I have a String and I would like to check that this string is > 0
using assert
trying :
using assertFalse I can't set 2 strings : my value and "0" .
Is there another way to say : assertThat "myString"> "0" ?
my purpose :
myTable.getValue =>this return a string : "20"
I would like to check that this string is > or different from "0"
thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
为了安全起见,您确实想将比较作为数字进行。所以你想要类似的东西
You really want to do the comparison as a number, for safety. So you want something like
此外,您可能想要使用
assertThat
样式:您需要导入
org.assertj.core.api.Assertions.assertThat
静态方法。我更喜欢这种方法,因为它可以增强测试的可读性。Additionally, with
assertThat
style you may want to use:you will need to import
org.assertj.core.api.Assertions.assertThat
static methods. I'd prefer this method as enhance test readability.