我有这样的包装纸。
public static void ShouldContain(this string str, string subStr)
{
Assert.That(str, Contains.Substring(subStr));
}
是否可以对该包装器进行单元测试?通过添加TestCase属性,我能够对它通过进行单元测试:
[TestCase("Hello world","world",
Description= "This test case will pass, because the Assert will be successful")]
public static void ShouldContain(this string str, string subStr)
{
Assert.That(str, Contains.Substring(subStr));
}
但是当我尝试另一个否定的TestCase时,由于断言失败,我的否定TestCase失败了。
我可以使用ExpectedException
TestCase属性的参数对其进行测试:
[TestCase("Hello world","world")]
[TestCase("Hello world", "bye", ExpectedException = typeof(AssertionException))]
public static void ShouldContain(this string str, string subStr)
{
Assert.That(str, Contains.Substring(subStr));
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句