开发者

How do I generate test data? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.

Want to improve this question? Update the question so it focuses on one problem only by editing this post.

开发者_开发知识库

Closed 5 years ago.

Improve this question

I have a class, is there a way to quickly generate a lot of objects from this class with random data?


You can generate test data using NBuilder

Through a fluent, extensible interface, NBuilder allows you to rapidly create test data, automatically assigning values to properties and public fields that are of type of the built in .NET data types (e.g. ints and strings).


You may checkout AutoFixture.


user reflection to go through all properties and set random value to it. somethig like this

object classObject;
PropertyInfo[] propertyInfos;
propertyInfos = typeof(classObject).GetProperties(BindingFlags.Public | BindingFlags.Static);
foreach (PropertyInfo propertyInfo in propertyInfos)
{
     propertyInfo.SetValue(classObject, value, null)
}


Visual Studio has inbuilt support for test data generation. This is targetted at database population, but once in a database it would be easy to do a little code generation.

See http://msdn.microsoft.com/en-us/library/dd193262.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜