我已閱讀過有關在單元測試中爲使用生成自動值但無法找到它的庫的信息。基本上,我想要的是不是:C#庫自動爲單元測試生成值
[Test]
public void Test()
{
int x = 2;
int y = 5;
Assert.AreEqual(7, ObjectUnderTest.Add(x, y));
}
我想寫:
[Test]
public void Test()
{
int x = Lib.Int();
int y = Lib.Int();
Assert.AreEqual(x + y, ObjectUnderTest.Add(x, y));
}
更新:
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));
}
謝謝貝里爾,AutoFixture是我正在尋找的。 – tvbusy
如果他回答了你的問題,你應該這樣標記。 – UrbanEsc