kay*_*yak 52 c# testing unit-testing
在C#中我怎样才能测试大于条件?
即,如果记录计数大于5,则测试成功.
任何帮助表示赞赏
码:
int actualcount = target.GetCompanyEmployees().Count
Assert. ?
Run Code Online (Sandbox Code Playgroud)
Wix*_*Wix 106
Assert.IsTrue(actualCount > 5, "The actualCount was not greater than five");
Run Code Online (Sandbox Code Playgroud)
NKn*_*rer 12
使用nUnit时执行此操作的正确方法是:
Assert.That(actualcount , Is.GreaterThan(5));
Run Code Online (Sandbox Code Playgroud)
小智 5
xUnit:如果您知道上限(例如 =100),您可以使用:
Assert.InRange(actualCount, 5, 100);
Run Code Online (Sandbox Code Playgroud)
这取决于您使用的测试框架。
对于xUnit.net:
Assert.True(actualCount > 5, "Expected actualCount to be greater than 5.");
对于NUnit:
Assert.Greater(actualCount, 5);
; 但是,新语法
Assert.That(actualCount, Is.GreaterThan(5));
被鼓励。
对于MSTest:
Assert.IsTrue(actualCount > 5, "Expected actualCount to be greater than 5.");