1
我想使用REST-assured來測試我的REST API而不是Spring的MockMvc。在REST-有保證的情況下執行asyncDispatch()
這個想法是,我想從使用REST保證庫的異步調用的響應中獲得狀態碼。
下面檢查細節:
我使用這些依賴關係:
'io.rest-assured:rest-assured:3.0.5'
'io.rest-assured:spring-mock-mvc:3.0.5'
當我這樣做:
mockMvc.perform(asyncDispatch(result)).andExpect(status().isAccepted());
我能夠得到低於此狀態代碼(輸出的.andDo(print())
)但我想用REST -Height達到相同的結果:
Async:
Async started = true
Async result = <202 Accepted,{}>
休息,放心,我只能夠得到下面這個狀態代碼:
MockHttpServletResponse:
Status = 200
Error message = null
Headers = {}
Content type = null
Body =
Forwarded URL = null
Redirected URL = null
Cookies = []
我試着這樣說:
given()
.accept(MediaType.APPLICATION_JSON_UTF8_VALUE)
.contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)
.body(new ObjectMapper().writeValueAsString(fineDto))
.when()
.put(URL)
.then()
.apply(print())
.expect(request().asyncStarted())
.expect(request().asyncResult(notNullValue()))
.expect(status().isAccepted());
測試失敗:
java.lang.AssertionError: Status
Expected :202
Actual :200
在此先感謝