C#unit testing,如何testing大于
在C#中,我怎么能unit testing一个大于条件?
即,如果logging数大于5,则testing成功。
任何帮助表示赞赏
码:
int actualcount = target.GetCompanyEmployees().Count Assert. ?
Assert.IsTrue(actualCount > 5, "The actualCount was not greater than five");
使用nUnit时正确的方法是:
Assert.That(actualcount , Is.GreaterThan(5));
可以与任何可比types一起使用的通用解决scheme:
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; }
actualCount.Should().BeGreaterThan(5);
在XUnit它是:
[Fact] public void ItShouldReturnErrorCountGreaterThanZero() { Assert.True(_model.ErrorCount > 0); }