测试类中的模拟类
2022-09-01 14:33:57
我如何与Mockito模拟我班级中正在测试的其他班级?
例如:
我的班级.java
class MyClass {
public boolean performAnything() {
AnythingPerformerClass clazz = new AnythingPerformerClass();
return clazz.doSomething();
}
}
AnythingPerformerClass.java
class AnythingPerformerClass {
public boolean doSomething() {
//very very complex logic
return result;
}
}
并测试:
@Test
public void testPerformAnything() throws Exception {
MyClass clazz = new MyClass();
Assert.assertTrue(clazz.performAnything());
}
我可以欺骗从中排除不必要的逻辑吗?我可以重写简单返回的方法吗?AnythingPerformerClass
AnythingPerformerClass
doSomething()
true
false
为什么我指定Mockito,因为我需要它来测试Robolactric的Android。