【发布时间】:2016-08-17 10:33:14
【问题描述】:
我正在研究 junit 并使用 PowerMockRunner 来模拟静态方法。
我知道可以使用when(...).thenReturn(...) 模拟静态方法
我需要模拟一个接受四个参数的方法:
public static void addInputPath(String, Boolean, Integer, Double)
我需要将此方法的任何调用中的第三个参数(整数)替换为10。所有其他参数都应该按原样传递。
换句话说,我需要做这样的事情:
when(addInputPath(str, bool, intgr, dbl)).thenReturn(addInputPath(str, bool, 10, dbl));
有没有办法做到这一点?
【问题讨论】:
-
这个问题在这个线程中得到了回答:stackoverflow.com/questions/5462096/…
-
我不相信你可以替换一个参数,你可以做的是为给定的集合参数给出你的方法的返回值
-
@kolakao 不确定这是否是我想要的。简化了我的问题。
-
@NicolasFilotto 你能给我举个例子吗?
标签: java unit-testing junit powermock