簡體   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