当使用AssertWasCalled来验证已使用特定参数调用方法时,恕我直言,犀牛模拟产生不清楚的诊断消息。
例:
interface ISomeInterface
{
void Write(string s);
}
[TestFixture]
public class SomeTests
{
[Test]
public void WriteShouldBeCalledWithCorrectArguments()
{
// Arrange
var mock = MockRepository.GenerateMock<ISomeInterface>();
var sut = new SomeClass(mock);
// Act
sut.DoSomething();
// Assert
mock.AssertWasCalled(x => x.Write(Arg<string>.Is.Equal("hello")));
}
}
现在,如果测试失败并显示此消息......
Rhino.Mocks.Exceptions.ExpectationViolationException:ISomeInterface.Write(等于hello);期望#1,实际#0。
......你不知道它是否失败,因为
A.'写'永远不会被调用 - 或 -
B.事实上,“写”是用不正确的参数调用的
如果B是失败的原因那么如果消息读取的内容会更加清晰:
Rhino.Mocks.Exceptions.ExpectationViolationException:ISomeInterface.Write(string arg):调用了方法,但参数不正确:预期:hello,Actual:bye
我可以自己解决这个缺点(通过某种方式为Rhino编写自定义匹配器)或者我只需要为此编写一个手动模拟器吗?