【发布时间】:2016-07-04 08:56:18
【问题描述】:
如何在方法中覆盖对象创建?
public class ClassToTest {
public Object testMethod() {
... code ...
Object result;
try {
result = new ClassToMock(someParam).execute();
} catch (Exception e) {
// handle error
}
return result;
}
}
我的测试如何覆盖 ClassToMock 的“执行”方法?我会很高兴使用 EasyMock 的代码示例。我想测试“testMethod”,比如:
@Test
public void testMethodTest(){
ClassToTest tested = new ClassToTest();
// Mock ClassToMock somehow
tested.testMethod();
// Verify results
}
【问题讨论】:
-
抱歉,为了生产截止日期夜以继日地工作......
-
不必感到抱歉!有时人们只是忘记了问题已经得到回答并且可以被接受。我也发生过。
标签: java unit-testing junit easymock