gpt4 book ai didi

java - JMockit : Inspect local variables of a method

转载 作者:行者123 更新时间:2023-11-30 09:44:43 24 4
gpt4 key购买 nike

是否可以在 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com