我一直在看這個一個小時,似乎無法看到有什麼問題。JSONObject單元測試總是空的
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("JSON", "hi");
String myString = jsonResponse.getString("JSON");
assertEquals("hi", myString);
結果...(整個方法拋出Throwable)。我嘗試了try/catch。相同的結果....
java.lang.AssertionError:
Expected :hi
Actual :null
這是我使用
public class ECUserTests(){
@org.junit.Test
public void testUserExists(){
try{
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("JSON", "Hello, World!");
String myString = jsonResponse.getString("JSON");
assertEquals("hi", myString);
}catch(JSONException e){
e.printStackTrace();
}
你可以發佈可運行的最小程序代碼嗎?我將上面的代碼放到Java類中併成功運行。 (我唯一的修改是將assertEquals更改爲Assert.assertEquals。) – cherdt
剛添加它。謝謝 –
您的問題的答案在這裏:http://stackoverflow.com/a/35675861/3032209 –