首页 > 解决方案 > Groovy 类可以用作 FitNesse 固定装置吗

问题描述

我正在学习 FitNesse 框架,想知道是否可以用 Groovy 编写夹具代码。所以我复制了一个示例决策表,将原始类重命名为ShouldIBuyMilkJava并创建了一个具有相同功能的 Groovy 类。所以我的设置是这样的:

wiki 测试页面(为简洁起见省略了表格行):

|should I buy milk Java                                         |
|cash in wallet|credit card|pints of milk remaining|go to store?|
|0             |no         |0                      |no          |
|10            |no         |0                      |yes         |

|should I buy milk Groovy                                       |
|cash in wallet|credit card|pints of milk remaining|go to store?|
|0             |no         |0                      |no          |
|10            |no         |0                      |yes         |

应该买牛奶Java.java

此处相同,只是将类重命名为ShouldIBuyMilkJava

应该购买MilkGroovy.groovy

class ShouldIBuyMilkGroovy {
    def dollars
    def pints
    boolean creditCard

    ShouldIBuyMilkGroovy() {

    }

    // the rest is omitted for brevity

这两个类都编译成功,并且位于测试页面中作为类路径导入的文件夹中。第一个测试成功通过,但第二个我得到一个异常Could not invoke constructor for ShouldIBuyMilkGroovy[0]

我尝试从 Groovy 类中删除一个空的无参数构造函数——结果相同。

如何让 Groovy 类作为 FitNesse 固定装置工作?

标签: groovyfitnessefitnesse-slim

解决方案


所以,修复很简单——我必须将!path指向 groovy 库的指令包含到 FitNesseroot页面中,而不是包含在测试页面中。


推荐阅读