【发布时间】:2021-06-29 03:55:40
【问题描述】:
我正在开发 Eclipse 插件,我需要对其进行一些测试。 我想在我的测试类中监视 Eclipse 运行时平台 API。 我的例子中提到的场景很容易理解。
Class MyClass{
private boolean foo(){
if (Platform.inDebugMode())
{
return false;
}
else{
return true;
}
}
}
Now I need to test foo() method completly
class MyClassTest{
MyClass myClass = new MyClass();
@Test
public void testFoo(){
assertTrue(myClass.foo());
}
@Test
public void testFooWithDebugMode(){
Mockito.doReturn(true).when(Platform).inDebugMode(); // Is this possible to mock this?
assertFalse(myClass.foo());
}
}
【问题讨论】:
-
实际问题是什么?你知道
Mockito::mockStatic吗? -
不多,但我的问题是我需要在不使用powermockito的情况下模拟静态方法
-
你看过上面的评论了吗?来看看
mockStatic怎么样?
标签: java eclipse junit mockito platform