[英]How do I load a customcomparator in a fitnesse test
I created a custom comparator for Fitnesse, and attempted to load it, but I can't get it to work. 我为Fitnesse创建了一个自定义比较器,并尝试加载它,但无法使其正常工作。 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]. 仅最后一次检查失败,返回:[那里的某些东西]预期的[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. 我遵循了http://fitnesse.org/FitNesse.SuiteAcceptanceTests.SuiteSlimTests.TestCustomComparators和http://www.fitnesse.org/FitNesse.UserGuide.AdministeringFitNesse.ConfigurationFile中的示例来进行深入介绍,但我找不到更多有关此文档。
尝试通过plugins.properties文件注册自定义比较器。
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. 对于那些(像我一样)在应用接受的答案和以下问题后仍无法正常工作的人:如果您使用fitnesse-standalone.jar
运行fitnesse,则仅在plugins
目录的jar文件中寻找plugins
。 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. 另外, URLClassLoader
用于查看jar文件的内部,因此请确保类文件位于与其包相对应的目录中。 For example, the jar file containing ContainsComparator
from the question should have the following directory structure: 例如, ContainsComparator
问题中的ContainsComparator
的jar文件应具有以下目录结构:
.
+-- com
+-- company
+-- ContainsComparator.class
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.