以下是我的課如何使用PowerMock部分模擬公共方法?
public class SomeClass {
public ReturnType1 testThisMethod(Type1 param1, Type2 param2) {
//some code
helperMethodPublic(param1,param2);
//more code follows
}
public ReturnType2 helperMethodPublic(Type1 param1, Type2 param2) {
//some code
}
}
所以在上面的類在測試testThisMethod(),我想部分模擬helperMethodPublic()。
截至目前,我做了以下內容:
SomeClass someClassMock =
PowerMock.createPartialMock(SomeClass.class,"helperMethodPublic");
PowerMock.expectPrivate(someClassMock, "helperMethodPublic, param1, param2).
andReturn(returnObject);
編譯器不抱怨。所以我嘗試運行我的測試,當代碼碰到helperMethodPublic()方法時,控件進入方法並開始執行那裏的每行代碼。我如何防止這種情況發生?
是這個工程,我這樣做,到現在爲止。但是,由於我使用的框架已經對私人幫手方法進行了部分嘲諷,因此必須有辦法部分嘲笑公共幫手方法嗎? – maverick
謝謝你,這是我遇到的類似問題的完美解決方案。我永遠不會擁有這種輝煌的技術! –