1

I created a custom comparator for Fitnesse, and attempted to load it, but I can't get it to work. It's just completely ignored in my script table, and it does a direct string equality comparison.

Comparator:

package com.company;
import fitnesse.testsystems.slim.CustomComparator;

public class ContainsComparator implements CustomComparator{

    @Override
    public boolean matches(String actual, String expected) {
        if(actual != null && actual.contains(expected)){
            return true;
        }
        else{
            return false;   
        }
    }
}

Test Page contents:

!define TEST_SYSTEM {slim}
!path C:\Path\To\My\Comparator.jar

!|Import|
|fitnesse.fixtures|

!| SetUp | CustomComparators=contains:com.company.ContainsComparator |

!|Script|com.company.SomeFixture|
|check| response|contains:something|

Only the last check fails, returning: [Something there] expected [contains:Something]. There's no other exceptions or failures (Setup doesn't throw an error, for example)

I followed examples from http://fitnesse.org/FitNesse.SuiteAcceptanceTests.SuiteSlimTests.TestCustomComparators and http://www.fitnesse.org/FitNesse.UserGuide.AdministeringFitNesse.ConfigurationFile to get this far, but I can't find any further documentation on this.

Mike Stockdale
  • 5,256
  • 3
  • 29
  • 33
user814005
  • 413
  • 2
  • 4
  • 12
  • 1
    I have not tried this but: have you tried registering the custom comparator via the plugins.properties file (instead of the SetUp fixture, a quick look in the code does not give me the impression this works outsides FitNesse's own acceptance tests)? – Fried Hoeben Jan 20 '16 at 19:31
  • You're right Fried. Adding the comparator reference to the plugin.properties file (and the comparator code to the plugins folder) worked. If you change your comment into an answer I'll give you the credit. Thanks! – user814005 Jan 21 '16 at 10:42

2 Answers2

2

Try registering the custom comparator via the plugins.properties file.

Fried Hoeben
  • 3,247
  • 16
  • 14
0

For those who (like me) were still not able to get this working after applying the accepted answer and the comments on the question: if you run fitnesse using fitnesse-standalone.jar, plugins are only looked for within jar files in the plugins directory. Placing class files there won't work.

Also, a URLClassLoader is used to look inside the jar files, so make sure the class file is inside directories corresponding to its package. For example, the jar file containing ContainsComparator from the question should have the following directory structure:

.
+-- com
    +-- company
        +-- ContainsComparator.class