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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 19:22:19  来源:igfitidea点击:

Is there any framework for .NET to populate test data?

c#.nettddpopulate

提问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

Take a look at NBuilder. It lets you build test objects with random data, incrementing values, and anything you can probably think of. All through a nice fluent interface.

看看NBuilder。它允许您使用随机数据、递增值以及您可能想到的任何内容构建测试对象。所有通过一个漂亮流畅的界面。

回答by Ronnie Overby

Yes there is. I found this when watching session #3 of the Summer of NHibernateseries by Stephen Bohlen.

就在这里。我在观看Stephen BohlenSummer 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:

知名且受人尊敬:

Little-known:

鲜为人知:

Unfamiliar:

陌生: