Is there any way in AutoFixture so that fixture.Create<string>()
will yield the same result? I.e., can I initialize the fixture with a seed?
Update
To be more precise, I'm looking for a random value generator that is initialised with some random seed, which is also outputted if a test fails. Thus, I can take the seed for that particular test run, and run the test with the fixed seed again. The seed should apply to all instances, regardless of their types. I think this is the most powerful way to use random values in tests, because it has a huge coverage, and is also reproducible.
You're looking at a feature called freezing:
var alwaysTheSameString = fixture.Freeze<string>();
If you want, you can also freeze a string
based on a seed value of yours:
var alwaysTheSameFooString = fixture.Freeze<string>("foo");
Keep in mind that AutoFixture only uses the provided seed value when asked to create strings. If you want to use a seed value for any other type you'll have to customize it yourself.
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