我热爱代码
关于Mockito的高级用法
@Test
public void MCAPB010JobTest14() throws BusinessException {
MCAPB010Job mockJob = Mockito.spy(job);
EntryUploadHistoryManager mockManager = Mockito.spy(entryUploadHistoryManager);
mockJob.setEntryUploadHistoryManager(mockManager); //重点
String argument = "2" + "," + "requestId";
File tradeFile = new File("D:\\csv\\xxx.csv");
doReturn(null).when(mockManager).get(Mockito.anyLong());
int status = mockJob.execute(argument, FileTobyte(tradeFile), null); //重点
TestCase.assertEquals(status, 1);
}
关于Mockito的个人心得(小技巧)
1_适用接口和类
PrefecturesMasterManager prefecturesMasterManagerMock = Mockito.spy(PrefecturesMasterManager.class);
2_只适用类(类时1和2可以相互转换)
@Autowired
private PrefecturesMasterManager prefecturesMasterManager;
PrefecturesMasterManager prefecturesMasterManagerMock = Mockito.spy(prefecturesMasterManager);;