C# .NET 是否有任何框架来填充测试数据?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1610212/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any framework for .NET to populate test data?
提问by ilker Aksu
I am use c# and for unit testing and integration testing usually I need to populate fields automatically based on attributes.
Lets say we will test if we can write and get back user data to database.
我使用 c# 进行单元测试和集成测试,通常我需要根据属性自动填充字段。
假设我们将测试是否可以将用户数据写入数据库并将其取回。
- I create a user object populate fields write user to database
- Read user object from database
- Check fields if what I write is same as what I read
- 我创建了一个用户对象填充字段将用户写入数据库
- 从数据库读取用户对象
- 检查字段是否我写的和我读的一样
Is there any framework to populate user with test data automatically and check if two object are have the same values?
是否有任何框架可以自动使用测试数据填充用户并检查两个对象是否具有相同的值?
Sample code may like this
示例代码可能是这样的
User user = new User();
AutoPopulator.Populate(user);
user.Save();
采纳答案by Michael Baldry
回答by Ronnie Overby
Yes there is. I found this when watching session #3 of the Summer of NHibernateseries by Stephen Bohlen.
就在这里。我在观看Stephen Bohlen的Summer of NHibernate系列的第 3 节时发现了这一点。
His company, Microdesk, has developed a utility that will allow you to save the state of a database on test fixture construction, set the state of the database at the start of every test, and recover the original state of the database on test fixture deconstruction.
他的公司Microdesk开发了一个实用程序,允许您在测试夹具构建时保存数据库的状态,在每次测试开始时设置数据库状态,并在测试夹具解构时恢复数据库的原始状态.
Download the utility here: Microdesk.Utility.UnitTest
在此处下载实用程序:Microdesk.Utility.UnitTest
For a tutorial on how to use it, watch the Summer of NHibernate session #3 video.
有关如何使用它的教程,请观看 Summer of NHibernate session #3 视频。
回答by Martin R-L
Fluent NHibernate has a feature which gives you everything on your wish-list, except the auto-population part:
Fluent NHibernate 有一项功能,可以为您提供愿望清单上的所有内容,除了自动填充部分:
Link: http://wiki.fluentnhibernate.org/Persistence_specification_testing
链接:http: //wiki.fluentnhibernate.org/Persistence_specification_testing
However, given C# with code contracts, it wouldn't be to hard to auto-magically create valid objects yourself using reflection.
但是,考虑到带有代码契约的 C#,使用反射自己自动神奇地创建有效对象并不难。
回答by Igor Toporet
You might find it relevant. Here is a list of few other frameworks as of today:
您可能会发现它相关。以下是截至今天的其他几个框架的列表:
Well-known and respected:
知名且受人尊敬:
- NBuilder
- AutoFixture
- AutoPoco
- Bogus- C# port of faker.jswith locale support. Used by Elasticsearch (NEST).
- NBuilder
- 自动夹具
- AutoPoco
- Bogus-具有语言环境支持的faker.js 的C# 端口。由 Elasticsearch (NEST) 使用。
Little-known:
鲜为人知:
Unfamiliar:
陌生:
- TestDataGenerator
- TestDataFactory(Discontinued)
- TestData
- Any-.Net