gpt4 book ai didi

为单元测试自动生成值的 C# 库

转载 作者:太空狗 更新时间:2023-10-29 22:20:20 24 4
gpt4 key购买 nike

我读到过一个库,该库生成用于单元测试的自动值,但找不到它。基本上,我想要的是:

[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));
}

最佳答案

我想你可以使用 PEX !

Pex automatically produces a small test suite with high code coverage for a .NET program. To this end, Pex performs a systematic program analysis (using dynamic symbolic execution, similar to path-bounded model-checking) to determine test inputs for Parameterized Unit Tests. Pex learns the program behavior by monitoring execution traces. Pex uses a constraint solver to produce new test inputs which exercise different program behavior.

关于为单元测试自动生成值的 C# 库,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6774556/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com