tvb*_*usy 5 c# tdd unit-testing
我已经读过一个库,它可以在单元测试中生成自动值,但无法找到它.基本上,我想要的不是:
[Test]
public void Test()
{
int x = 2;
int y = 5;
Assert.AreEqual(7, ObjectUnderTest.Add(x, y));
}
Run Code Online (Sandbox Code Playgroud)
我想写:
[Test]
public void Test()
{
int x = Lib.Int();
int y = Lib.Int();
Assert.AreEqual(x + y, ObjectUnderTest.Add(x, y));
}
Run Code Online (Sandbox Code Playgroud)
更新:
AutoFixture是我正在寻找的.使用AutoFixture,我的测试将是:
[Test]
public void Test()
{
var fixture = new Fixture();
int x = fixture.CreateAnonymous<int>();
int y = fixture.CreateAnonymous<int>();
Assert.AreEqual(x + y, ObjectUnderTest.Add(x, y));
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2772 次 |
最近记录: |