问题描述
我想测试私有方法的功能。 而且我还想检查参数何时为“ null”
是否可以通过使用JMockit测试私有方法? 我该怎么办?
目的:我想测试所有案例以符合覆盖率测试的要求。
实际代码
@Test
public void testLogic() throws illegalaccessexception,IllegalArgumentException,InvocationTargetException,NoSuchMethodException,SecurityException {
Service serviceTest = new Servicetest();
int expected = false;
Method method = Service.class.getDeclaredMethod("testMethod",String.class,String.class) ;
method.setAccessible(true);
boolean actual = (boolean)method.invoke(serviceTest,"aaa",new Object[]{null});
assertEquals(false,actual);
}
测试代码
private boolean testMethod(String test,String testNull) throws IOException
{
if(testNull== null)
{
return false;
}
return true;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)