UnitTest JSONObject显示为空 [英] UnitTest JSONObject shows null

查看:204
本文介绍了UnitTest JSONObject显示为空的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了与JSONObject有关的问题.

I have got a problem connected with JSONObject.

@Test
public void toUrlTest() throws JSONException {
    String url;

    JSONObject json = new JSONObject();

    json.put"id", 1);
    json.put("email", "test@hotmail.com");
    url = JSONParser.toURLString(json);

    assertEquals("id=1&email=test@hotmail.com", url);

}

问题是当我调试此测试时,它表明没有任何内容放入json对象.

The problem is when I am debugging this test, it shows that nothing is put to json object.

json = {org.json.JSONObject@826}空"

json={org.json.JSONObject@826} "null"

我检查了所有内容,却不知道为什么会这样. JSONObject在应用程序中可以正常工作.它只会在测试时发生.

I checked everything and I got no clue why this happen. JSONObject works fine in app. It only happens while testing.

PS. 我已经在build.gradle中添加了

PS. I have added in build.gradle this

 testOptions {
        unitTests.returnDefaultValues = true
        } 

推荐答案

TL; DR版本的Yair Kukielka的回应...(谢谢!)

TL;DR version of Yair Kukielka's response... (thanks!)

按照

testCompile "org.json:json:20140107"

这将用在桌面上可用的库替换已存根的Android库.

This will replace the stubbed Android library with one that works on the desktop.

这篇关于UnitTest JSONObject显示为空的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆