Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Dummy ObjectList generator for unit testing

Can anyone inform whether there is any good framework in c# that will generate dummy objects and lists so that we don't need to generate the stub data manually?

like image 686
maeenul Avatar asked Apr 18 '26 20:04

maeenul


1 Answers

You can try NBuilder. It's purpose is rapid generation of test objects.

If you have Employee class:

public class Employee
{
    public string Name { get; set; }
    public DateTime Birthday { get; set; }
} 

Generating list of 10 Employee object is simple like this:

var employees = Builder<Employee>.CreateListOfSize(10).Build();

It will generate unique incremental values for all fields of object:

Name1 7/12/2012
Name2 7/13/2012
Name3 7/14/2012
...

Also NBuilder has nice powerful fluent interface, which allows to setup custom values for any generated object:

var employees = Builder<Employee>.CreateListOfSize(10)
    .TheFirst(1).With(e => e.Name = "Sergey")
    .All().With(e => e.Address = Builder<Address>.CreateNew().Build())
    .Build();

Also you can take a look at:

  • Autofixture
  • AutoPoco
  • Symply Test Data
like image 122
Sergey Berezovskiy Avatar answered Apr 21 '26 11:04

Sergey Berezovskiy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!