Heuristics for Static Factory Methods in AutoFixture

Crossposted from my personal blog.

Here is a type with a private constructor:

In order to create an instance of that type we have to call one of it’s static factory methods, for example:

If we try to create an Anonymous Variable with AutoFixture right now (version 2.1) it will throw an exception since there are no public constructors:

Using the latest version from trunk (and on the next public release) the above code will work. It will successfully return an instance of the type by using a set of heuristics that enable AutoFixture to search for static factory methods.

The latest build (including strong names) can be downloaded from here.

Leave a Reply