我收到断言错误,说它得到406
并预期为200
。不确定如何解决此问题。为了您的信息,我正在尝试将Spring Boot 1.5.2升级到2.1.4
下面是我的代码-
@ContextConfiguration(classes = ChangeController.class)
@WebAppConfiguration
public class ChangeControllerTest extends AbstractJUnit4SpringContextTests {
private MockMvc mockMvc;
@Autowired
private WebApplicationContext wac;
@Before
public void setup() {
this.mockMvc = MockMvcBuilders.webAppContextSetup(wac).build();
}
@Test
public void verifyInvalidToDoArgument() throws Exception {
mockMvc.perform(MockMvcRequestBuilders.get("/log").accept(MediaType.APPLICATION_JSON))
.andExpect(status().isOk())
.andDo(print());
}
}
控制器类
@Controller
@RequestMapping("/log")
public class ChangeController {
@ApiIgnore
@RequestMapping(method = RequestMethod.GET, produces = {"text/plain"})
public
@ResponseBody
String generate() {
return "some string is here
";
}
}
下面是控制台响应-
java.lang.AssertionError: Status
Expected :200
Actual :406