我正在为 spring mvc 项目进行junit测试,我可以为get和post方法创建测试方法,就像下面的get方法示例一样,现在我需要为delete方法进行测试,我得到了这个错误
(类型 myclassTest 未定义方法 DELETE(String, Long))
本教程使用删除没有错误
@Test
public void testGetOne() throws Exception {
ResultActions perform = mockMvc.perform(get(
MachineWebservice.URL+"/{id}",1)
);
perform.andDo(print())
.andExpect(status().isOk())
;
}
最佳答案
您只是没有静态导入该成员(在 MockMvcRequestBuilders
中声明的 static
delete
方法)。因此,编译器认为该方法应该存在于它所使用的类 myclassTest
中,但事实显然并非如此。
将适当的import
语句添加到您的测试类
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
关于java - 使用 spring mvc 在 junit 测试中删除方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30624427/