我需要知道如何在JMockit中使用withInstanceOf来模拟私有方法? 这是我需要测试的类。 package mockingPrivateMethodWithInstanceOf;
public class Simple
{
private String iAmPrivate(String argString)
{
return "Private Method";
}
public String publicCallsPrivate()
{
String string = "aString";
return iAmPrivate(string);
}
}
这是测试类
public class SimpleTest
{
@Test
public void testPublicInvokesPrivate()
{
final Simple simple = new Simple();
new Expectations(simple)
{
{
Deencapsulation.invoke(simple, "iAmPrivate", withInstanceOf(String.class));
returns("Mocked method");
}
};
assertEquals("Mocked method", simple.publicCallsPrivate());
}
}
执行测试类时,它说:
java.lang.IllegalArgumentException: Invalid null value passed as argument 0