在C#我怎样才能单元测试比条件更大?C#单元测试,如何测试大于
即,i如果记录数超过5测试成功更大。
任何帮助表示赞赏
代码:
int actualcount = target.GetCompanyEmployees().Count
Assert. ?
在C#我怎样才能单元测试比条件更大?C#单元测试,如何测试大于
即,i如果记录数超过5测试成功更大。
任何帮助表示赞赏
代码:
int actualcount = target.GetCompanyEmployees().Count
Assert. ?
Assert.IsTrue(actualCount > 5, "The actualCount was not greater than five");
A G eneric解决方案,它可以与任何可比的类型可以使用:
public static T ShouldBeGreaterThan<T>(this T actual, T expected, string message = null)
where T: IComparable
{
Assert.IsTrue(actual.CompareTo(expected) > 0, message);
return actual;
}
中的xUnit是:
[Fact]
public void ItShouldReturnErrorCountGreaterThanZero()
{
Assert.True(_model.ErrorCount > 0);
}
但最好把一条消息,让你知道为什么测试失败:Assert.IsTrue(actualCount> 5,“actualCount不超过五”); – McKay 2010-11-09 20:20:54
谢谢,它解决了 – kayak 2010-11-09 20:21:12
@McKay:我个人发现这是浪费精力。如果测试失败,无论如何我都会查看它的代码,所以即使失败时也不会节省很多时间*并且大多数断言在第一次签入IME后永远不会失败。 – 2010-11-09 20:23:23