Thursday, May 20th, 2010

Mock Data Randomizer

Category: Testing

Mike Wilcox has written about a nice little tool for folks who test their JavaScript code. The Mock Data Randomizer is fairly self-explanatory:


  1. rand.sentences(6,7,7,9); // # of words in sentences
  2. rand.real = true;
  3. rand.sentences(6,7,7,9);

would generate something like:

Whut koop mida miins knew eftor kind. Deys evin thaaght has plecu uthur melos. Eftor shaeld ha lift hend wath ets unto big. Huwovir till lergi wa kind olsa con bofare. Yaor sentonca sean cemu man in whoch man. Mi sentonca nught get fund very onswar tui plecu. Shew en geed liva knew poiplu childrun ilung gat.

Far night very land room for then we. First kind turned out is own usually back much. Read sometimes since does answer himself into much. Live not for large hand important they. People another sea across across even world. Water could things young by white own only very.


  3.{delimiter:"/", yearRange:-5});
  5.{min:new Date('11/20/1964'), max:"4/19/1969", delimiter:"-"});

would generate something like:

Mon Feb 14 2011 14:13:17 GMT-0800 (PST)

Check out the live demo to see it in action and then view the source.

Posted by Dion Almaer at 6:16 am

3 rating from 2 votes


Comments feed TrackBack URI

This is awesome! Haven’t had a chance to use it yet, but I can’t tell you how many times I wish I had something like this. I’m usually left to cobbling together something quickly on my own, but this seems like it will be much more elegant to use.

Comment by notmessenger — May 20, 2010

Clean and mean. Can’t wait to try this out!

Comment by gacord — May 20, 2010

Can’t tell you how many times I have worked on the UI for some app to only get embarrassed later because I didn’t test variable length data. This is really nice and light weight. It’s one of those nice little tools that you think about writing, but never get to. Thanks!

Comment by donaldlsmithjr — May 20, 2010

Very nice! My own (open source GNU) data generation script:

Comment by AtomicPenguin — May 20, 2010

I don’t really like that Idea. I like my tests to be reproducible and complete. Randomizing values makes tests reproducible and probably makes you think less about border cases.

Comment by 29a — May 21, 2010

@29a: The only problem with your tests being reproducible is that your own tests fail to think like anyone but you. I have written several web applications that start their life being completely perfect in my eyes. It’s only when the stupid users come in and type stupid things into my perfect fields that I actually find the majority of the errors.

Comment by starkraving — May 30, 2010

Leave a comment

You must be logged in to post a comment.