but was: org. json.JSONObject< {"feedback":[]}>-6ren"> but was: org. json.JSONObject< {"feedback":[]}>-我编写了一个具有一个条件的方法的测试。根据条件,它应该为空,并且返回空响应,但存在断言错误。 @Test public void testExtractData_feedbackRecords_wit-6ren">
gpt4 book ai didi

java.lang.AssertionError : expected: org. json.JSONObject< {"feedback":[]}> but was: org. json.JSONObject< {"feedback":[]}>

转载 作者:行者123 更新时间:2023-12-02 09:53:06 26 4
gpt4 key购买 nike

我编写了一个具有一个条件的方法的测试。根据条件,它应该为空,并且返回空响应,但存在断言错误。

@Test 
public void testExtractData_feedbackRecords_withBadWords() throws Exception {
//given
JSONArray tags = new JSONArray();
tags.put("ios_pre");
tags.put("andr_pre");
tags.put("web_pre");

JSONObject jsonObject = new JSONObject();
jsonObject.put("group_id", "28430278");
jsonObject.put("created_at", "2019-04-05T00:00:00Z");
jsonObject.put("updated_dt", "");
jsonObject.put("status", "status-test");
jsonObject.put("ticket_id", "1");
jsonObject.put("id", "1");
jsonObject.put("description", "----- Sender Info ----- Body:body1 adult platform=platform1");

JSONArray feedbackRecords = new JSONArray();
feedbackRecords.put(jsonObject);

JSONArray empty = new JSONArray();
JSONObject expected = new JSONObject();
expected.put("feedback", empty);

ZendeskExtractor mockZendeskExtractor = PowerMockito.mock(ZendeskExtractor.class);
PowerMockito.doReturn(feedbackRecords)
.when(mockZendeskExtractor, "extractFeedback", Mockito.any(String.class), Mockito.any(String.class));
when(mockZendeskExtractor.extractData("2019-04-05T00:00:00Z", DateTime.parse("2019-04-25T00:00:00Z")))
.thenCallRealMethod();

//when
JSONObject actualData =
mockZendeskExtractor.extractData("2019-04-05T00:00:00Z", DateTime.parse("2019-04-25T00:00:00Z"));

//then
assertEquals(expected, actualData);
}

出现以下错误:

java.lang.AssertionError: expected: org.json.JSONObject<{"feedback":[]}> but was: org.json.JSONObject<{"feedback":[]}>

最佳答案

尝试改变你的断言,例如:

assertEquals(expected.toString(), expected2.toString());

现在应该可以通过测试了。详情请click here

关于java.lang.AssertionError : expected: org. json.JSONObject< {"feedback":[]}> but was: org. json.JSONObject< {"feedback":[]}>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56174582/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com