I am writing an exporting function to take data from a database table and export to text. Before I plug the code into the rest of the app I would like to test the export based on random data created in c#. I have found many examples in SO about creating test data in a database but none that was created directly in code. Does anybody have an example or know of a link to one?
Thanks
How to Create Test Data? Test data can be created: Manually: This is the most common way and mostly created in an excel sheet, where testers need to consider test Scenarios and test conditions and use the combinations correctly. Word files, Text Files, XML files can also be used to create test data.
Test data is data that is used to test whether or not a program is functioning correctly. The test data is input, the program is processed and the output is confirmed. Whenever possible, test data should cover a range of possible and impossible inputs , each designed to prove a program works or to highlight any flaws.
You can use AutoFixture to generate pseudo-random data directly from C# code.
It is a convention-based and extensible library that uses reflection to populate objects with data.
It can be used as simply as this:
Fixture fixture = new Fixture();
MyClass mc = fixture.CreateAnonymous<MyClass>();
After the second line of code, the mc
instance will be populated with all appropiate constructor parameters, and all writable properties will have been assigned.
It supports nested hierachies, non-default constructors, mapping from interfaces to concrete types and many other things.
You can customize it (almost) to your heart's content as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With