Thursday, May 20th, 2010
Mock Data Randomizer
<>p>
Mike Wilcox has written about a nice little tool for folks who test their JavaScript code. The Mock Data Randomizer is fairly self-explanatory:
-
-
rand.sentences(6,7,7,9); // # of words in sentences
-
rand.real = true;
-
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.
-
-
rand.date();
-
rand.date({seconds:true});
-
rand.date({delimiter:"/", yearRange:-5});
-
rand.date({delimiter:"/"});
-
rand.date({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)
1296270214154
08/04/2005
10/10/2010
02-05-1967
Check out the live demo to see it in action and then view the source.
Related Content:











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.
Clean and mean. Can’t wait to try this out!
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!
Very nice! My own (open source GNU) data generation script:
http://www.generatedata.com/#generator
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.
@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.