![](/img/trans.png)
[英]java.lang.AssertionError: expected:<200> but was:<404> in jersey restful services unit test
[英]java.lang.AssertionError: Status expected:<200> but was:<404> in restful services
我正在尝试对下面的程序进行单元测试,但报错为:java.lang.AssertionError:预期状态:<200>,但状态为:<404>
测试类别:
package com.hsbc.mvc;
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {WebAppContext.class})
@WebAppConfiguration
public class ControllerTest {
@Autowired
private WebApplicationContext context;
private MockMvc mvc;
@Before
public void before() {
MockitoAnnotations.initMocks(this);
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).dispatchOptions(true).build();
}
@Test
public void testMyMvcController() throws Exception {
this.mvc.perform(get("/newcontroller")).andExpect(status().isOk());
}}
控制器:
@RestController
public class HelloController {
@RequestMapping("newcontroller")
public ModelAndView firstPage() {
System.out.println(" Inside Hello Controller ....");
return new ModelAndView("index");
}}
这是您应该寻找的一些东西:
server.servlet-path
和server.context-path
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.