【发布时间】:2014-07-16 07:25:56
【问题描述】:
我正在编写一个单元测试用例,其中我无法比较两个字符串,因为对象内部有</> 标签。
我的输出是
{"description":"<p>License forms information can be download as attachments<\/p>"}
我的预期输出是:
"{\"description\":\"<p>License forms information can be download as attachments</p>\"}";
我遇到问题的唯一地方是</p> 标签。当我更改为 <\/p> 时,它会引发语法错误。任何建议将不胜感激。
我的代码
WebResource webResource = client.resource("http://myip:8080/Kalgudi/restService");
ClientResponse response = webResource.type("application/xml").get(ClientResponse.class);
String output = response.getEntity(String.class);
JSONObject json = new JSONObject(output);
System.out.println("Json object is:"+json.getJSONObject("6824"));
String expected = "{\"description\":\"<p>License forms information can be download as attachments</p>\"}";
assertEquals(expected, json.getJSONObject("6824"));
【问题讨论】:
-
嗯,也许测试用例代码是个好主意?
-
@cyborg,用我的代码更新。请检查一下。
-
好的,所以无法回答这个问题,因为我们根本不知道您的 Web 服务正在做什么来生成带有不正确结束标记的 JSON。这大概是您需要担心的系统。
标签: java unit-testing