使用Mockito从void函数中获取局部变量的值
我有一个类似的方法:
public void process {
ArrayList<String> data = new ArrayList<>();
...
...
}
data
是一个本地变量,在调用myobject.process()
中,我要在测试功能中访问它的值。我有什么办法可以做到吗?
I have a method like below:
public void process {
ArrayList<String> data = new ArrayList<>();
...
...
}
data
is a local variable, the value of which I want to access after calling myObject.process()
inside the test function. Is there any way I can do that?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Mockito无法访问由您的代码创建的本地变量。测试代码的唯一方法是检查该变量是否正在实现其他事物并验证该更改。这个答案应该可以帮助您。
https://stackoverflow.com/a/a/30188745/17052051
Mockito cannot access a local variable which is created by your code. The only way to test the code is to check whether something else is being effected by that variable and verify that change. This answer should help you out.
https://stackoverflow.com/a/30188745/17052051