Can I regenerate random values ​​in AutoFixture using a seed?

Is there a way in AutoFixture that fixture.Create<string>() gives the same result? Ie, is it possible to initialize the device using a seed?

Update

To be more precise, I am looking for a random value generator that is initialized with some random seed, which is also output if the test fails. So I can take the seed for this particular test run and run the test with the fixed seed again. Seed should apply to all instances, regardless of type. I think this is the most powerful way to use random values ​​in tests, because it has huge coverage and is also reproducible.

+6
source share
1 answer

You are looking at a function called freezing :

 var alwaysTheSameString = fixture.Freeze<string>(); 

If you want, you can also freeze string based on the initial value:

 var alwaysTheSameFooString = fixture.Freeze<string>("foo"); 

Keep in mind that AutoFixture only uses the given initial value when prompting for strings. If you want to use the initial value for any other type, you must configure it yourself .

+4
source

Source: https://habr.com/ru/post/986663/


All Articles