Dummy ObjectList generator for unit testing
Asked Answered
I

5

3

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?

Impregnable answered 12/7, 2012 at 7:12 Comment(0)
C
6

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:

Conny answered 12/7, 2012 at 8:22 Comment(0)
H
1

The framework I like to use and does what you ask is the following: Rhino Mocks

This is for C#, and its superior.

Hung answered 12/7, 2012 at 7:56 Comment(0)
M
0

The framework I like to use and does what you ask is the following: Unitils

but then again, I don't know for which programming language you are asking ? The one proposed is for Java.

Mosora answered 12/7, 2012 at 7:14 Comment(2)
I was looking for something in C#. Is there any?Impregnable
Sadly I don't know anything about the C# language sorry.Mosora
C
0

If you need to create fake implementations of interfaces or abstract classes then there's a bunch of "mocking frameworks" available. One of them is Rhimo Mocks mentioned by Harry. For you as a beginner in this area I'd also suggest Moq as it's more straightforward compared to Rhino Mocks (IMHO).

Civvies answered 12/7, 2012 at 8:30 Comment(0)
S
0

Everyone likes realistic fake data, use Bogus library.

var faker = new Faker("en");

var emailList = Enumerable.Range(1, 5)
      .Select(_ => faker.Internet.Email())
      .ToList();

//OUTPUT:
[email protected]    
[email protected] 
[email protected] 
[email protected]   
[email protected]
Saddler answered 23/6, 2021 at 12:6 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.