How do I generate test data? [closed]
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 questionI 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
精彩评论