1
我想模擬枚舉的所有實例的方法shouldShow()。有人可以幫助如何做到這一點。模擬枚舉java的所有實例的方法
public enum MyButton implements ListButton {
Button1(
R.drawable.drawable1) {
// Some methods here
},
Button2(
R.drawable.drawable2) {
//Some methods here
};
@Override
public boolean shouldShow() {
//Some logic that decides whether to show the button or not
}
}
我想嘲弄它這樣如果我叫Button1.shouldShow或Button2.shouldShow,或enum.shouldShow任何其他值,我的存根應返回true。
你想通過這樣做完成什麼?我的理解是,你不能以這種方式嘲笑枚舉,但通常你仍然可以通過其他方式實現你想要的測試。 –
shouldShow方法包含一組靜態。我知道我可以使用powermock來測試函數,但是我將不得不模擬很多靜態方法。我試圖避免這樣做,以某種方式嘲弄shouldShow函數本身。 – Prateek
抱歉誤會;這不是我所問的。在你的測試案例中,你試圖嘲笑這種方法,你在測試什麼?那個測試用例的更廣泛的目標是什麼? –