繁体   English   中英

测试方法中的Easymock多种方法调用

[英]Easymock multiple method calls inside the test method

因此,我正在使用easymock在类内部编写方法的单元测试。 我已经在此方法中模拟了一个对象,并且效果很好。 问题出在这个测试方法内部,我在同一个类中多次调用其他方法。

例如,

public class testClass { 
    public void testMethod() { 
        mockedObject.method(); --> I define a return type for this and it works fine.
        this.otherMethod() {
        --> Inside this method I have a call to the mocked object with different methods..
    }
}

所以我的问题是,当该方法通过使用this.otherMethod()调用另一个方法时,我是否应该在otherMethod内定义mockedObject调用的所有返回值? 是否没有办法为otherMethod指定返回值,以便它甚至不会进入其他方法? 请注意,这里不是模拟对象,这就是为什么我不能使用eaymock返回值的原因。 我当时在想也许有办法解决这个问题。

谢谢。

更新:我发现这是为了部分模拟方法: http : //www.easymock.org/EasyMock2_2_2_ClassExtension_Documentation.html仅有助于模拟特定方法。 但是,当我尝试使用它时,它在createMock方法上越过一行。

感谢大家,

我找到了此链接: http : //fczaja.blogspot.com/2011/11/easymock-create-partial-mocks.html

答案是部分模拟在此方法内调用的那些方法,以隔离这些方法调用。

再次感谢。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM