JMockit:检查方法的局部变量
是否可以检查 JMockit 中方法的局部变量?
来源
void foo(){
boolean isPresent = false;
/// ... something here sets isPresent
}
测试
can I check the value of isPresent at the end of call of foo() using JMockit?
Is it possible to inspect local variables of a method in JMockit?
Source
void foo(){
boolean isPresent = false;
/// ... something here sets isPresent
}
Test
can I check the value of isPresent at the end of call of foo() using JMockit?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
而不是尝试做一些晦涩的模拟机制。尝试将代码重构为可以测试的内容:
另外,请考虑这一点。如果变量的值永远不会逃逸该方法并且不会引起其他影响(应该是可测试的),为什么要尝试测试它呢?或者为什么它会在那里?测试方法作用域变量的值为 x 没有任何值。测试该方法的结果是否为 y,因为变量 x 具有值。
Rather than trying to do some obscure mocking mechanism. Try refactoring the code to something that you can test:
Also, consider this. If the variable's value never escapes the method and does not cause some other effect (which should be testable), why try to test it? Or why is it even there? Testing that a method scope variable's value is x has no value. Testing that the method resulted in y because the variable was x has value.