By Peng Xie
Let the monkeys out!
Of course we’re talking about monkey tests here… There are actually two types of monkeys — the smart monkeys and the dumb monkeys.
A smart monkey, knows the application it is testing, and follows a certain set of rules when it comes to doing its job. A dumb monkey, like its name suggests, knows pretty much nothing and behaves more randomly. One can think that a monkey in real life is probably somewhere between our smart monkey and dumb monkey.
There are advantages and disadvantages for both types of monkeys. A smart monkey, while being more effective to find bugs, does require more effort to “train”. The developer needs to create the said knowledges and rules for the smart monkey before it can start the tests. A dumb monkey is more likely to find random, out-of-the-box bugs. But thanks to its unpredictability, the bugs found by a dumb monkey may be harder to reproduce. Some would even question the value of monkey tests since it may take a long time before they can find any bugs.
I think monkeys are important friends of developers. Here’s a story:
Xuanzang finished his app. He used test-driven development procedures and wrote all the unit tests for all components of his app, including “comprehensive” UI tests. (At least that was what he thought.) His app passed all tests with flying colors. He were happy and released it to the public. A day later, weird UI related crash reports started to show up in his inbox. People had given his app negative reviews. And he were no longer happy.
“Why? The app passed all tests!” exclaimed Xuanzang.
His monkey friend came and touched a part of the UI that “a normal user would not think of touching.”
The app crashed.
The monkey friend relaunched the app and long pressed a button that “a normal user would just tap.”
The app crashed again.
You see, the monkey is not a “normal user.” As developers, it’s easy (and absolutely normal) to assume a certain user behavior when making test cases. Because we designed the app to function in a set boundaries, we may be blind to some behaviors outside of the box. A wise man once told me, when it comes to test cases, if you think you are already crazy enough, the real life will always out-crazy you. To save our sanity (and time), we need to ask our monkey friends for help.
“Where can we make friends with the monkeys then?”
A lot of places actually. Not in the zoos though…
If you are an Android developer, your monkey friends are actually living right in your Android Studio! They run on your emulator or devices to produce random streams of user events.
For iOS developers, Apple has yet to introduce us any monkey friends. But we do have SwiftMonkey that lives in GitHub. It even has a framework called
SwiftMokeyPaws to let you see where your monkey friends have touched in real time in your app’s UI.
Those are only a few examples. If you search, you can always find a monkey friend with a very particular set of skills…