December 31, 2013

Sophistries when using AutoFixture...

I often use AutoFixture for creating objects when testing. But sometimes you have some special needs which AutoFixture doesn't support out-of-the-box. I have collected some of these below (this list will be updated when I find other special needs):

When using AutoFixture you allways have to create a new instance of the Fixture class...

Fixture fixture = new Fixture();

Get a string of fixed length

When using AutoFixture to fillout string properties, the default behavior is to join the name of the property with a Guid. But sometimes you have to use some fixed size strings - to achieve this you can use the following code:

var stringOfSize10 = string.Join(string.Empty, fixture.CreateMany<char>(10));

Note: It seems that some of my earlier findings have been corrected in a later version of AutoFixture and has therefore been removed from the list ...

No comments:

Post a Comment