我有这样的包装。
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失败了,因为断言失败。
答案 0 :(得分:0)
我可以使用TestCase属性的ExpectedException
参数进行测试:
[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));
}