我想测试ClassToTest该类的方法methodToTest。但是我无法使它成为anotherMethod被调用的私有方法与单例类使用其公共方法methodToTest返回的值有一些依赖关系。SingletonClassgetName
我尝试使用 powermock 的 privateMethod 模拟和静态方法模拟等等,但没有帮助。
有没有人有这种情况的解决方案?
Class ClassToTest{
public void methodToTest(){
...
anotherMethod();
...
}
private void anotherMethod(){
SingletonClass singletonObj = SingletonClass.getInstance();
String name = singletonObj.getName();
...
}
}