在以下 Spock 测试中:
def 'simple assertion'() {
expect:
Math.max(a, b) == max
where:
a | b | max
3 | 5 | 5
4 | 9 | 9
}
在 Expect block 的代码行中设置断点时,在调试时无法从 Evaluate Expression... 对话框访问变量 (a, b)
的值。返回的异常为:
groovy.lang.MissingPropertyException: No such property: a, b for class: DUMMY
解决这个问题的唯一方法是手动将 where
部分中的数据复制到求值表达式对话框中。
如何使用评估表达式而无需从测试的where
部分手动复制值?
我使用在 macOS 12 Monterey 上运行的 IntelliJ IDEA Ultimate 2022.1,并使用 Groovy 版本 4 和 Gradle 作为构建工具。
最佳答案
当我显式声明参数时,它对我有用。
def 'simple assertion'(int a, int b, int max) {
expect:
Math.max(a, b) == max
where:
a | b | max
3 | 5 | 5
4 | 9 | 9
}
关于java - 在 IntelliJ IDEA 中调试时,无法在“评估表达式”对话框中访问 Spock 测试的变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72249172/