question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Autobogus does not respect calls to Randomizer.Seed or UseSeed

See original GitHub issue

Unit and integration tests should generally be deterministic (see here; with the potential exception of cases where one is specifically trying to implement randomized tests as a form of exploratory testing).

The base Bogus library provides for this as described here, namely either by:

  • setting the Randomizer.Seed global static property; or
  • calling the Faker<T>.UseSeed(int) method.

However, Autobogus does not appear to respect either of these methods of deterministically creating fake data. I have tried both of the approaches without success, as exemplified below:

// Author class
public class Author
{
    public int Id { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }

    // Navigation properties
    public ICollection<Book> Books { get; set; }
}

// Global seed configuration
Randomizer.Seed = new Random(8675309);

// Local seed configuration
const int seed = 1234;
var authorFaker = new AutoFaker<Author>()
	.Configure(builder => builder
		.WithSkip<Author>(a => a.Id)
		.WithSkip<Author>(a => a.Books))
	.UseSeed(seed);

// Check output using LINQPad
authorFaker.Generate().Dump();

In both cases, the data output differs on each run. If I use Bogus without Autobogus, I am able to create deterministic data without any issues.

Is it currently possible to generate deterministic data with Autobogus or, if not, is it possible to add this feature? Despite the library offering a lot of other useful features, currently we cannot use it because of a requirement to create deterministic data.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:11 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
nickdodd79commented, Oct 18, 2020

Hey @zejji

I have updated the issue you reference in you comment. Currently the UseSeed is not hooked up to the underlying Faker used by the AutoFaker class. I will get a change in place to make that so and let you know when it has been released.

Nick.

0reactions
logiclrdcommented, Aug 4, 2022

Am I misunderstanding – by running the tests in parallel, aren’t they pulling numbers concurrently from the same underlying source??

Read more comments on GitHub >

github_iconTop Results From Across the Web

Can I specify the random seed for Bogus?
Randomizer.Seed = new Random(8675309);. However, setting the seed means that the results of the random generator are consistent.
Read more >
Easily Generate Sample Data for Testing Using Bogus and ...
The generated output is there, although we can see that the names and email addresses are all very random and not what we...
Read more >
Bogus
Bogus is a simple fake data generator for .NET languages like C#, F# and VB.NET. Bogus is fundamentally a C# port of faker.js...
Read more >
Fake data substitution for tests in C# with Bogus
Creates a seed locally scoped within this Faker{T} ignoring the globally scoped Randomizer.Seed. If this method is never called the global ...
Read more >
Aesthetically - OSCHINA - 中文开源技术交流社区
Data visualization is a science but that doesn't mean it has to be ugly. One of the big efforts we've made while creating...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found