为什么 spock 模拟 void 方法不起作用
Why spock mocking void method does not work
在规范中我想模拟 class:
com.univocity.parsers.csv.CsvParser
我试着这样做:
parser = Stub()
parser.stopParsing() >> null
或
parser.stopParsing() >> {}
没有任何效果。
总是调用原始的class方法。
我用 Groovy 的 2 和 3 版本试过了,并修正了 Spock 版本。
a) 我需要做什么才能完成这项工作?
b) 我可以在文档信息中找到关于
为什么要为 Stub 或 Mock 调用原始 class 方法?
Spock 无法模拟 final
类 and/or 方法和 CsvParser as well as stopParsing() are final. You can try using the spock mockable 扩展来使那些 classes/methods 非 final
.
在规范中我想模拟 class:
com.univocity.parsers.csv.CsvParser
我试着这样做:
parser = Stub()
parser.stopParsing() >> null
或
parser.stopParsing() >> {}
没有任何效果。
总是调用原始的class方法。
我用 Groovy 的 2 和 3 版本试过了,并修正了 Spock 版本。
a) 我需要做什么才能完成这项工作?
b) 我可以在文档信息中找到关于 为什么要为 Stub 或 Mock 调用原始 class 方法?
Spock 无法模拟 final
类 and/or 方法和 CsvParser as well as stopParsing() are final. You can try using the spock mockable 扩展来使那些 classes/methods 非 final
.