Go faster! Linking data generation to hotkeys

Sometimes testing is like pouring a bucket of confetti on a snow leopard. Have you ever tried pouring a bucket of confetti on a snow leopard? Probably not, but now that the thought occurs to you, don’t you really want to know what happens? That’s like testing – you want to know what happens when you do something. But before you can shower the snow leopard with confetti, you have to buy the confetti, steal the bucket, walk to the zoo, distract the guards, break into the leopard enclosure and lure the leopard out with kitty treats. It’s pretty tedious stuff, and all you wanted to do was the fun stuff at the end. Don’t you wish there was a shortcut?

Tenuous metaphors aside, shortcuts to do tedious stuff are full of win and not difficult to set up. If you already use tools to automate tests, it’s just a matter of making some handy methods to do common tasks. Do you already have a test that steals buckets for you? Just modify it so that you can substitute whatever values you need to help you do your manual testing and hey presto, you’re already well on your way to pouring paper on an endangered species.

My latest fad is to link up data generation to hotkeys. If you’re using a Mac, you can use the lovely Keyboard Maestro for this. Otherwise if you’re on Windows (like I am), you can use the less glamorous AutoHotkey, which gave my antivirus software a small panic attack when I installed it (which I just ignored, with no dire consequences so far). Once installed, take a look at the tutorial. It’s quite easy to follow.

At my work, we already had a few little data generation scripts written in Ruby, so it was a simple matter to hook them up to some hotkeys using AutoHotkey, like so:

[cc]#w::Run ruby random_words.rb 2
#e::Run ruby random_email.rb trishk
#c::Run Ruby random_campaign.rb[/cc]

Respectively, these lines do the following:
Windows key + w = Generates 2 random words and copies them to my clipboard.
Windows key + e = Generates a randomized email address that will still point to my account and copies it to my clipboard.
Windows key + c = Randomly selects a URL from a list of test email campaigns and copies it to my clipboard.

That’s everything I need to fill out most forms in the application I’m testing. So when I just need safe, unique inputs, I can save a few seconds on each screen while filling in forms. More importantly, I don’t have to break my focus in order to find or generate appropriate test data.

The great thing about this is that shortcuts are so easy to set up and modify. I could have several hotkey files, each one like a utility belt for the feature I’m testing. Perhaps tomorrow I will have to run a suite of tests that each need a fresh user account with different configurations. I could link a few keyboard shortcuts to API calls that create a new user, and each different shortcut could correspond to a different configuration.