我想编写一个 JUNIT 测试用例来检查一个字符串是否只包含数值。 任何人都可以建议我这样做。我是 junit 测试用例的新手,我找不到任何方法为其编写断言。 请提出建议。
谢谢,
最佳答案
使用Integer.parseInt(string)
。如果字符串包含数字以外的字符,则方法将抛出 NumberFormatException
。
try{
Integer.parseInt(inputString)
}catch(NumberFormatException exception){
//assert fail
}
关于java - 断言检查字符串只包含数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24651903/