Monday, August 22, 2016

Using AutoFixture in your Unit Tests

If you are writing Unit Tests, you may frequently run into a need to autogenerate test or dummy data for your Unit Tests.

For many cases, you can use a framework such as NBuilder, however, NBuilder has numerous limitations in that it is primarily geared towards generating test data for classes which have default class constructors, but it is not as useful for generating test data for primitive types such as strings and integers.

So what do you do in those cases?  Well, that is where AutoFixture ( comes in!

AutoFixture is available as a NuGet package and fills in many of the gaps that are left by a framework such as NBuilder.  It allows the generation of random strings and integers as well as allowing the generation of test objects in a manner similar to NBuilder:

No comments:

Post a Comment