是否可以在 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?
最佳答案
而不是试图做一些晦涩的模拟机制。尝试将代码重构为您可以测试的内容:
void foo(){
boolean isPresent = isPresent();
}
boolean isPresent(){
....
}
此外,请考虑这一点。如果变量的值永远不会逃脱方法并且不会引起其他影响(应该是可测试的),为什么要测试它?或者为什么它甚至在那里?测试方法作用域变量的值为 x 没有任何值(value)。测试方法结果为 y,因为变量 x 具有值。
关于java - JMockit : Inspect local variables of a method,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7708099/