Introduction to Bogus - A Fake Data Generation Library

Why we need to generate fake data

While working with our applications we need to generate fake data for different purposes.

  • For testing purpose (especially unit testing)
  • For demonstration of data maybe for charts/graphs
  • Dumping the data in databases

What is the Bogus and benefits of using it

If you come from JS world then you would be aware about faker.js Bogus is C# version of that library.

Bogus is a Nuget package available on Nuget Package Manager with approximately 46M downloads.

These are the benefits of Bogus :

  1. Compatible with C# , F# and VB.NET

  2. Supported in 50 international languages

  3. It comes with a variety of data e.g. addresses,commerec,companies,database,finance,dates,images,vehicles and many more

  4. It has some country based extensions as well for different countries (e.g. Brazil,Norway,Finland,Italy and few more)

  5. It has premium packages as well for movies,tvs,literature,medical and diagnosis details

  6. It gives us the facility to apply variety pf rules on data according our need

  7. Its really simple to use it and you don’t need any lengthy process , just install package and use it

How to use it in .NET Core

  • Step 1 : Install Nuget Package with name Bogus (With 45.3 M Downloads)

  • Step 2 : Make rules for your fake model

  • Step 3 : Call Generate method of library to generate data

Let’s see with code now for better understanding

Simple Demonstration of Bogus

In this example you can check all list of properties/methods available in library in second part of expression(RuleFor)

Introduction to Bogus - A Fake Data Generation Library

How to Generate N’ Fake Entries

We can pass an integer in parameter to Generate method and it will create that much entries.

Introduction to Bogus - A Fake Data Generation Library

How to Generate Same Data Every Time

Bogus gives us the facility to create same data every time by defining a random number of our choice like this .

Introduction to Bogus - A Fake Data Generation Library

How to Generate Data in Other Languages

Introduction to Bogus - A Fake Data Generation Library

By default data is generated in “en” but you can pass language code of your choice to generate data in your language . Check language list from Bogus GitHub Repo

This is a just basic overview of library , covering each and everything is not possible , I would recommend you to visit GitHub repository of the library and you can find the things which you need.

This article was originally published at https://mwaseemzakir.substack.com/ on .

Whenever you're ready, there are 3 ways I can help you:

  1. Subscribe to my youtube channel : For in-depth tutorials, coding tips, and industry insights.
  2. Promote yourself to 9,000+ subscribers : By sponsoring this newsletter
  3. Patreon community : Get access to all of my blogs and articles at one place