亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

請教老師:如何在controller中通過json測試呢

老師您說:可以測試json,就好奇問問。如何編寫。

正在回答

2 回答

有沒有好心人幫助看一下呀

0 回復 有任何疑惑可以回復我~
public?interface?ResultActions?{

???/**
????*?Perform?an?expectation.
????*
????*?<h4>Example</h4>
????*?<pre?class="code">
????*?static?imports:?MockMvcRequestBuilders.*,?MockMvcResultMatchers.*
????*
????*?mockMvc.perform(get("/person/1"))
????*???.andExpect(status().isOk())
????*???.andExpect(content().contentType(MediaType.APPLICATION_JSON))
????*???.andExpect(jsonPath("$.person.name").value("Jason"));
????*
????*?mockMvc.perform(post("/form"))
????*???.andExpect(status().isOk())
????*???.andExpect(redirectedUrl("/person/1"))
????*???.andExpect(model().size(1))
????*???.andExpect(model().attributeExists("person"))
????*???.andExpect(flash().attributeCount(1))
????*???.andExpect(flash().attribute("message",?"success!"));
????*?</pre>
????*/
???ResultActions?andExpect(ResultMatcher?matcher)?throws?Exception;

???/**
????*?Perform?a?general?action.
????*
????*?<h4>Example</h4>
????*?<pre?class="code">
????*?static?imports:?MockMvcRequestBuilders.*,?MockMvcResultMatchers.*
????*
????*?mockMvc.perform(get("/form")).andDo(print());
????*?</pre>
????*/
???ResultActions?andDo(ResultHandler?handler)?throws?Exception;

???/**
????*?Return?the?result?of?the?executed?request?for?direct?access?to?the?results.
????*
????*?@return?the?result?of?the?request
????*/
???MvcResult?andReturn();

}

看了一下源碼,我試試,請老師,伙伴們回復下

0 回復 有任何疑惑可以回復我~
#1

HeroChan 提問者

java.lang.AssertionError: No value at JSON path "$.person.name", exception: Missing property in path $['person'] body中可以顯示數據,但是報這個錯誤。我再看看,先去吃飯 了。
2017-08-06 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

請教老師:如何在controller中通過json測試呢

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號