Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mock Object Data

I'd like to mock up object data, not the objects themselves. In other words, I would like to generate a collection of n objects and pass it into a function which generates random data strings and numbers. Is there anything to do this? Think of it as a Lorem Ipsum for object data. Constraints around numerical ranges etc. are not necessary, but would be a bonus.

like image 343
Keith Adler Avatar asked May 12 '10 18:05

Keith Adler


2 Answers

The first thing I thought of when I read your question was QuickCheck, a testing tool for Haskell. In QuickCheck you specify properties (invariants) that your function should have, and you can specify valid ranges for inputs (plus a bunch more features), and QuickCheck will generate a bunch of random input data and throw it at your function and check too see if the output matches the specification. Nosing around a little I found out there is an F# port of it so QuickCheck exists in the .net world:

http://fscheck.codeplex.com/

There is also a MS Research project Pex that might be close to what you are thinking of:

http://research.microsoft.com/en-us/projects/Pex/

"...Pex finds interesting input-output values of your methods, which you can save as a small test suite with high code coverage. Microsoft Pex is a Visual Studio add-in for testing .NET Framework applications."

I haven't used it before, but it looked like it is good for generating edge case data that exercises any and all branches of a function. It actually analyzes a function rather than just throwing truly random stuff at it.

like image 186
Travis Brooks Avatar answered Sep 23 '22 18:09

Travis Brooks


There also appears to be a .NET port of the Ruby Faker gem, which gets a lot of use for rigging fake data objects in Ruby. I haven't used it, but it might be worth looking into:

https://github.com/slashdotdash/faker-cs

like image 32
CodingWithSpike Avatar answered Sep 20 '22 18:09

CodingWithSpike