1
我正在爲彈簧控制器編寫單元測試。我的控制器基於Rest API,我使用@RequestBody和@ResponseBody註釋來支持這一點。 使用@Mock註釋時,出現「註釋@Mock不允許用於此位置」錯誤。註解@Mock在春季junit測試用例中不允許用於此位置
我的測試類是象下面這樣:
@RunWith(SpringJunit4ClassRunner.class)
@WebAppConfiguration
Public class ControllerTest{
Controller1 controller1;
Public void init(){
controller1= new Controller1();
}
@Test
Public voidd test(){
ServiceAdaptorClass ServiceAdap= new MockUp<ServiceAdaptorClass>{
@Mock // getting error here that 「The annotation @Mock is disallowed for this location」
ReturnType methodname(arg1,arg2) throws Exception{
ReturnType returntype;
returntype.setProperty(…..);
return returntype;
}
}.getMockInstance();
mockmvc.perform("url");
}
}