我为System.Type创建了一个扩展方法,我想单元测试该方法。这可能吗?谢谢!这种类型为“Type”的扩展方法为空
public static bool GetFoo(this Type self)
{
if (self == null)
{
throw new ArgumentNullException("this")
}
...
}
我为System.Type创建了一个扩展方法,我想单元测试该方法。这可能吗?谢谢!这种类型为“Type”的扩展方法为空
public static bool GetFoo(this Type self)
{
if (self == null)
{
throw new ArgumentNullException("this")
}
...
}
断言((Type)null).GetFoo()
抛出。
MS VS单元测试
[TestMethod]
[ExpectedException(typeof(ArgumentNullException))]
public void TestFoo()
{
Type t = null;
t.GetFoo();
}
也适用!谢谢! – lionheart
你也可以这样做:
ExtensionClass.GetFoo(null)
编辑:刚才注意到,这是一样的杰森埃文斯现在删除的答案...
刚以其他方式延伸:
this.GetType().GetFoo();//inside some class.
typeof(SomeType).GetFoo();
由于它引发了ArgumentNullException,因此可以将它包装在正确的try-catch块中
+1击败我。 – Maarten
@Maarten:我很久没去过枪战了。不知道我是否仍然拥有它,以及我在沙龙里的所有时间...... – Will
太棒了。有效。 – lionheart