【发布时间】:2017-03-24 10:05:34
【问题描述】:
如何验证是否调用了printPreview.createShowReport();。我什至无法设置模拟对象,因为一旦我调用该方法,它就会实例化为 null 并创建新对象。
public void previewOrDirectPrint(File file, boolean val) {
try{
printPreview=null;
printPreview=new ExamReportPrintUI(this,file);
}
catch(Exception e){
e.printStackTrace();
}
if(!val)
{
printPreview.createShowReport();
}
else
{
printPreview.createHideReport();
printInitiate();
closeReportPreview();
}
here is my test case
@Test
public void testpreviewOrDirectPrint()
{
File file=new File("/Desktop/config/reportTemplate.html");
examReportManager.previewOrDirectPrint(file, false);
assertNotNull(Whitebox.getInternalState(examReportManager, "printPreview"));
}
Can anyone help me how to access the object or create mock and set to it. I can only verify if the object is mock.
我尝试使用Whitebox.setInternalstate("obj","",mockobject). 进行设置,但两个对象不同。
【问题讨论】:
标签: java unit-testing junit mockito powermockito