久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

EasyMock:無效方法

EasyMock: Void Methods(EasyMock:無效方法)
本文介紹了EasyMock:無效方法的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個方法在一個類中返回 void,該類是我要測試的類的依賴項.

I have a method that returns void in a class that is a dependency of the class I want to test.

這個類很大,我只使用其中的一個方法.我需要為測試替換此方法的實現,因為我希望它做一些不同的事情,并且我需要能夠訪問此方法接收的參數.

This class is huge and I'm only using this single method from it. I need to replace the implementation of this method for the test as I want it to do something different and I need to be able to access the parameters this method receives.

我在 EasyMock 中找不到這樣做的方法.我想我知道如何使用 Mockito 通過使用 doAnswer 但除非絕對必要,否則我不想添加另一個庫.

I cannot find a way of doing this in EasyMock. I think I know how to do it with Mockito by using doAnswer but I don't want to add another library unless absolutely necessary.

推薦答案

如果我理解你想做什么正確,你應該可以使用 andAnswer():

If I understand what you want to do correctly, you should be able to use andAnswer():

mockObject.someMethod(eq(param1), eq(param2));
expectLastCall().andAnswer(new IAnswer() {
    public Object answer() {
        //supply your mock implementation here...
        SomeClass arg1 = (SomeClass) getCurrentArguments()[0];
        AnotherClass arg2 = (AnotherClass) getCurrentArguments()[1];
        arg1.doSomething(blah);
        //return the value to be returned by the method (null for void)
        return null;
    }
});

EasyMock 用戶指南解釋道:

有時我們希望我們的模擬對象返回一個值或拋出一個在實際調用時創建的異常.從 EasyMock 2.2 開始,expectLastCall()expect(T 值) 提供方法 andAnswer(IAnswer answer) 允許 [you] 指定接口的實現 IAnswer 用于創建返回值或異常.

Creating Return Values or Exceptions

Sometimes we would like our mock object to return a value or throw an exception that is created at the time of the actual call. Since EasyMock 2.2, the object returned by expectLastCall() and expect(T value) provides the method andAnswer(IAnswer answer) which allows [you] to specify an implementation of the interface IAnswer that is used to create the return value or exception.

IAnswer 回調中,參數傳遞給模擬調用可以通過 EasyMock.getCurrentArguments().如果你使用這些,像重新排序參數這樣的重構可能會破壞你的測試.您已收到警告.

Inside an IAnswer callback, the arguments passed to the mock call are available via EasyMock.getCurrentArguments(). If you use these, refactorings like reordering parameters may break your tests. You have been warned.

這篇關于EasyMock:無效方法的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to mock super reference (on super class)?(如何模擬超級參考(在超級類上)?)
Java mock database connection(Java 模擬數據庫連接)
Mockito ClassCastException - A mock cannot be cast(Mockito ClassCastException - 無法投射模擬)
Set value to mocked object but get null(將值設置為模擬對象但獲取 null)
How to mock DriverManager.getConnection(...)?(如何模擬 DriverManager.getConnection(...)?)
Mockito; verify method was called with list, ignore order of elements in list(模擬;使用列表調用驗證方法,忽略列表中元素的順序)
主站蜘蛛池模板: 很黄很污的网站 | 久久久久久九九九九 | 国产精品高清在线 | 久久精品综合网 | 天天操夜夜操免费视频 | a视频在线观看 | 亚洲精品欧洲 | 国产精品不卡 | 国产色片在线 | 一区二区三区精品在线视频 | 亚洲一区精品在线 | 欧美a级网站 | 日韩免费一区 | 日韩中文字幕视频 | 国产精品日韩欧美一区二区三区 | 国产视频福利一区 | 国产日韩一区二区三免费 | 日本在线黄色 | 日日操夜夜操天天操 | 在线看片国产 | 狠狠狠干| 日韩在线免费视频 | 国产婷婷在线视频 | 成人在线视频网 | 婷婷综合色 | 久久久久久高潮国产精品视 | 91视频一区 | 日韩精品在线视频免费观看 | 91麻豆精品一区二区三区 | 亚洲一区二区久久久 | 岛国av一区二区三区 | 亚洲精品电影网在线观看 | 欧美老少妇一级特黄一片 | 欧美xxxⅹ性欧美大片 | 国产一区二区精品自拍 | 91av视频在线 | www.五月天婷婷 | 伊人精品在线 | 国产盗摄视频 | 免费久草 | 激情91|