[英]java.lang.AssertionError: Status expected:<200> but was:<404> in restful services
I am trying to unit test my program below but getting error as: java.lang.AssertionError: Status expected:<200> but was:<404> 我正在尝试对下面的程序进行单元测试,但报错为:java.lang.AssertionError:预期状态:<200>,但状态为:<404>
Test Class: 测试类别:
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());
}}
Controller: 控制器:
@RestController
public class HelloController {
@RequestMapping("newcontroller")
public ModelAndView firstPage() {
System.out.println(" Inside Hello Controller ....");
return new ModelAndView("index");
}}
Here are some things you should be looking for: 这是您应该寻找的一些东西:
server.servlet-path
and server.context-path
. 检查您的application.properties或application.yml中的server.servlet-path
和server.context-path
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.