Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java powermockito“;whenNew“;马上打电话回答_Java_Powermockito - Fatal编程技术网

Java powermockito“;whenNew“;马上打电话回答

Java powermockito“;whenNew“;马上打电话回答,java,powermockito,Java,Powermockito,当我使用PowerMockito.whenNew…然后回答-答案立即运行! 我的代码: 输出: kuku int test kuku int 如何解决这个问题。可能(我不确定)是PowerMockito在编译过程中而不是在运行时替换了整数构造函数,这会导致所有new Integer()调用都通过PowerMockito。上面的代码对我来说工作正常。我希望您在测试类@RunWith(PowerMockRunner.Class)@PrepareForTest({Integer.Class})上有这

当我使用
PowerMockito
.whenNew…然后回答-答案立即运行! 我的代码:

输出:

kuku int
test
kuku int

如何解决这个问题。

可能(我不确定)是PowerMockito在编译过程中而不是在运行时替换了整数构造函数,这会导致所有
new Integer()
调用都通过PowerMockito。上面的代码对我来说工作正常。我希望您在测试类
@RunWith(PowerMockRunner.Class)@PrepareForTest({Integer.Class})
上有这个选项。我得到了正确的输出:Test后跟kuku int
kuku int
test
kuku int