0

I am learning the FitNesse framework and wondering if fixture code can be written in Groovy. So I made a copy of an example Decision Table, renamed the original class as ShouldIBuyMilkJava and created a Groovy class with same functionality. So my setup is like this:

wiki test page (table rows omitted for brevity):

|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         |

ShouldIBuyMilkJava.java:

Same as here, except that the class is renamed to ShouldIBuyMilkJava

ShouldIBuyMilkGroovy.groovy:

class ShouldIBuyMilkGroovy {
    def dollars
    def pints
    boolean creditCard

    ShouldIBuyMilkGroovy() {

    }

    // the rest is omitted for brevity

Both classes are compiled successfully and are located in a folder that is imported as classpath in the test page. The first test passes successfully, but for the second I get an exception Could not invoke constructor for ShouldIBuyMilkGroovy[0].

I've tried removing an empty no-arg constructor from Groovy class - same result.

How can I make Groovy classes work as FitNesse fixtures?

  • Did you define the groovy class to be in a package? Do you have an import table that imports that package (i.e. tells FitNesse to look for classes in that package)? Did the 'execution log' give any details? I'm not very knowledgable about groovy but does it need any additional libraries to be on the classpath, are those all added to FitNesse's fixture classpath? – Fried Hoeben Apr 13 '20 at 20:11
  • @FriedHoeben, thanks for a comment :) Yeah, I put both classes (java and groovy) in the same package, which is imported by FitNesse test SetUp page. I've tried adding Groovy libraries to the classpath - no luck. I'll examine execution log more closely today and update y uestion accordingly. – Евгений Терехов Apr 14 '20 at 02:48
  • @FriedHoeben, your recommendation to examine execution log was super helpful, thanks a lot! I've found that classpath for SlimService didn't contain groovy libraries, although I've placed groovy ```!path``` directive on the test setup page. So I moved that ```!path``` to groovy library onto the ```root`` FitNesse page - and it worked. – Евгений Терехов Apr 14 '20 at 04:31

1 Answers1

0

So, the fix is simple - I had to include !path directive pointing at groovy library into FitNesse root page, not into the test page.