我想测试我的API并使用模拟。我有一种方法来测试我的API的良好组合:
@Test
@Transactional
public void requestShouldReturnCode200() throws Exception {
restMeteoMockMvc.perform(get("/api/myAPI/{param1},{param2}", GOOD_PARAM1, GOOD_PARAM2)
.accept(TestUtil.APPLICATION_JSON_UTF8))
.andExpect(status().isOk());
}
我想测试的方法的签名是:
@RequestMapping(value = "/api/myAPI/{param1},{param2}",
method = RequestMethod.GET,
produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<Object> get(@PathVariable Float param1, @PathVariable Float param2)
我认为我在发送测试方法参数的方式上犯了一个错误......不是吗? 因为在我的重定向文件中测试结果,我可以看到requestShouldReturnCode200收到了400个代码并且预计有200个。
requestShouldReturnCode200(com.bookstore.web.rest.MyClassResourceTest) Time elapsed: 0.032 sec <<< FAILURE!
java.lang.AssertionError: Status expected:<200> but was:<400>
at org.springframework.test.util.AssertionErrors.fail(AssertionErrors.java:60)
at org.springframework.test.util.AssertionErrors.assertEquals(AssertionErrors.java:89)
at org.springframework.test.web.servlet.result.StatusResultMatchers$10.match(StatusResultMatchers.java:653)
at org.springframework.test.web.servlet.MockMvc$1.andExpect(MockMvc.java:152)
at com.bookstore.web.rest. com.bookstore.web.rest.MyClassResourceTest.requestShouldReturnCode200(com.bookstore.web.rest.MyClassResourceTest.java:60)