153
votes

I found the following function in package android.app.ActivityManager.

public static boolean isUserAMonkey ()

The reference describes:

public static boolean isUserAMonkey () Since: API Level 8

Returns "true" if the user interface is currently being messed with by a monkey.

I was shocked by this strange function. And have a few questions.

  • What does this (user interface is currently being messed with by a monkey) mean?

  • What is the practical use of this function?

  • Why do they use isUserAMonkey for the function name?

2
There is no proper documentation. Then how can we use the function. They should get review on their documentation.Mahendran
according to answer by HefferWolf, this method is used for some automatic testing of android framework (i think), so we do not need to use this function at all.. so no need of PROPER documentation.gtiwari333
Shock the monkeyJeff Axelrod
It looks to me like test code that's leaked into production libraries, in this case the ActivityManager. Having your production code being knowledgeable of whether it is currently being tested, and presumably altering it's actions in any way based that knowledge works against the whole point of test code which easily leads to Hisenbugs. It also adds cruft to the API making it harder to understand and to maintain. The fact that this SO question even exists is evidence enough.Melinda Green
I laughed when I saw this methodMarcos Vasconcelos

2 Answers

104
votes
37
votes

The Monkey is a program that runs on your emulator or device and generates pseudo-random streams of user events such as clicks, touches, or gestures, as well as a number of system-level events. You can use the Monkey to stress-test applications that you are developing, in a random yet repeatable manner.

just refer these links also: