如何使用 rhino 模拟测试抽象类的构造函数中的空参数?
我有一个像这样的类:
public abstract class ClassA<T>
{
protected ClassA(IInterface interface)
{
if (interface== null)
{
throw new ArgumentNullException ("interface");
}
}
}
我想编写一个测试来验证是否在抛出异常中传递 null:
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public TestMethod()
{
ClassA classa = MockRepository.GenerateMock<ClassA<String>> (null);
}
但测试始终因异常而不是预期的异常而失败。我还尝试将调用包装在 try catch 块中,但出现同样的问题。我尝试了GenerateStub和PartialMock。
我缺少什么?
I have a class like so:
public abstract class ClassA<T>
{
protected ClassA(IInterface interface)
{
if (interface== null)
{
throw new ArgumentNullException ("interface");
}
}
}
I want to write a test which verifies that if I pass null in the exception is thrown:
[Test]
[ExpectedException (typeof (ArgumentNullException))]
public TestMethod()
{
ClassA classa = MockRepository.GenerateMock<ClassA<String>> (null);
}
but the test keeps failing with an exception rather than the exception being expected. I also tried wrapping the call in a try catch block, but same issue. I tried GenerateStub and PartialMock.
What am I missing?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最近自己也遇到了这个问题,不幸的是我无法找到任何方法来告诉Rhino不要自行包装异常。到目前为止,我能想到的最好的办法如下:
I've recently run into this issue myself, unfortunately I haven't been able to find any way to tell Rhino not to wrap the exception itself. Thus far, the best I've been able to come up with would be as follows: