我在寫一個使用Mockito的JUnit測試用例,我得到一個NullPointerException。Mockito引發的JUnit測試用例拋出NullPointerException
商業行爲準則
public XRImage getImage(String imgId, List tagList) {
_paramsMap.printContent();
return _paramsMap.getImage(imgId, tagList);
}
測試代碼
@Test
public void getImageTest() {
String imgId = new String("Test");
List requiredTags = null;
XRImage xRImage = Mockito.mock(XRImage.class);
ImageParamsMap imageParamsMap = Mockito.mock(ImageParamsMap.class);
imageParamsMap.addImage(imgId);
when(imageParamsMap.getImage(imgId, requiredTags)).thenReturn(Mockito.mock(XRImage.class));
XRImage getImage1 = acquisitionParamsManager.getImage(imgId, requiredTags);
assertNotNull(getImage1);
}
你如何初始化'acquisitionParamsManager'?你需要在這個對象中注入模擬 –
我使用@InjectMocks – bhavya