我试图使用JMockit模拟一个私有方法,并且正在努力。我一直在研究这些教程,并且可以模拟返回值的私有方法,而不是没有。此特定方法与数据库交互,不返回任何内容。出于本次测试的目的,我想要做的就是有效地掩盖这种方法。我正在使用的测试格式如下所示,请注意,通常在调用方法deencapsulation后结果将是直接的。
@Test
public void testRetrieveAndSaveReport() {
//Make class with private class final, to be used in the Exceptionsinners class
final ESReportOutputLogic eSReportOutputLogic = new ESReportOutputLogic();
// Define Expectations
// pass eSReportOutputLogic as argument to make it a Mocked type in the Exceptions Class
new Expectations(eSReportOutputLogic){
ESReportOutputLogic eSReportOutputLogic;
{
Deepcapsulation.invoke(eSReportOutputLogic);
}
};
ESReportOutputLogic rol = new ESReportOutputLogic();
rol.retrieveAndSaveReport("","",1);
// asserts.....
}
答案 0 :(得分:1)