2014-07-09 32 views
3

我想寫一個JUNIT測試用例來檢查一個字符串是否只包含數字值。 有人可以建議我這樣做。我是junit測試用例的新手,我發現找不到任何方法來爲它寫一個assert。 請建議。斷言檢查字符串只包含數字值

謝謝,

回答

1

使用Integer.parseInt(string)。如果字符串包含數字以外的字符,則方法將拋出NumberFormatException

try{ 
    Integer.parseInt(inputString) 
}catch(NumberFormatException exception){ 
    //assert fail 
} 
+2

befor it我想斷言整數檢查 – Romi

相關問題