I've read about a library that generates auto values for usage in unit test but could not find it. Basically, what I want was instead of:
[Test]
public void Test()
{
int x = 2;
int y = 5;
Assert.AreEqual(7, ObjectUnderTest.Add(x, y));
}
I want to write:
[Test]
public void Test()
{
int x = Lib.Int();
int y = Lib.Int();
Assert.AreEqual(x + y, ObjectUnderTest.Add(x, y));
}
Update:
AutoFixture is the one I'm looking for. With AutoFixture, my test will be:
[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));
}
I think you can use 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.
AutoPoco lets you generate objects for tests.
NBuilder is a great library for creating sets of test data and objects. It uses a fluent API so it's pretty easy, IMHO, to pick up and start working with it.
Like this (not compile tested):
[Test]
public void Test()
{
int x = Builder<int>.CreateNew().Build();
int y = Builder<int>.CreateNew().Build();
Assert.AreEqual(x + y, ObjectUnderTest.Add(x, y));
}
There's ways to create random data as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With