rest-auured斷言報錯Float與BigDecimal
阿新 • • 發佈:2021-07-14
本章講解使用rest-auured斷言出現型別不匹配Float與BigDecimal的解決方法
一般使用金額時都會精確到小數,在excel或者其他檔案中自定義的響應資訊時,json解析小數會自動設定為Float型別,而介面響應的小數型別是BigDecimal型別,
所以在斷言時會出現型別轉換異常,以下有幾種解決方法:
rest-auured文件官網:https://github.com/rest-assured/rest-assured/wiki/Usage
1、在斷言處對Float進行轉換成BigDecimal型別在比較
Float f = 5.02F; // 將Float型別轉為BigDecimalBigDecimal bigDecimal = new BigDecimal(f.toString()); System.out.println(bigDecimal.getClass()); System.out.println(bigDecimal);
2、第二種方法rest-auured官網也做了解決方案:需要在give()方法後面加上一個配置:config(RestAssured.config().jsonConfig(jsonConfig().numberReturnType(BIG_DECIMAL)))
: