用于单元测试的虚拟 ObjectList 生成器 [英] Dummy ObjectList generator for unit testing
问题描述
谁能告知c#中是否有好的框架可以生成虚拟对象和列表,这样我们就不需要手动生成存根数据?
你可以试试 NBuilder.其目的是快速生成测试对象.</p>
如果你有 Employee 类:
公共类员工{公共字符串名称{获取;放;}公共日期时间生日{得到;放;}}
生成 10 个 Employee 对象的列表很简单:
var Employees = Builder.CreateListOfSize(10).Build();
它将为对象的所有字段生成唯一的增量值:
Name1 7/12/2012姓名 2 7/13/2012名称3 7/14/2012...
NBuilder 也有很好的强大的流畅界面,它允许为任何生成的对象设置自定义值:
var Employees = Builder.CreateListOfSize(10).TheFirst(1).With(e => e.Name = "Sergey").All().With(e => e.Address = Builder.CreateNew().Build()).建造();
你也可以看看:
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?
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:
这篇关于用于单元测试的虚拟 ObjectList 生成器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!