我想问是否有办法在将字符串数据与表中的数据进行比较之前对其进行修剪。例如,如果我们有
|MyCompareClass|
|getString? |
|string1 |
getString() 的结果将是“string1”。我希望比较是绿色的,而不是预期的“string1”。我正在寻找一种无需修改 MyCompareClass 源代码的方法。有任何想法吗?
您可以编写自定义字符串比较运算符类:
public class MyCustomCompare: CellOperator, CompareOperator<Cell> {
public bool CanCompare(TypedValue actual, Tree<Cell> expected) {
return actual.Type == typeof(string);
}
public bool Compare(TypedValue actual, Tree<Cell> expected) {
return actual.Value.ToString().Trim() == expected.Value.Text;
}
}
Fitnesse
然后使用配置夹具注册您的类:
|configure|processor|add operator|MyCustomCompare|
你可以放进!-string1 -!
你的牢房。我能想到的所有其他选项都涉及对 SUT 或夹具的代码更改。