Visit Sponsor

Written by 11:42 am Android

Android Monkey Stress Test – Using UI/Application Exerciser

Stress testing an Android application helps ensure stability under unpredictable and heavy user interactions. The UI/Application Exerciser Monkey is a built-in Android SDK tool that generates a pseudo-random stream of user events (touch, clicks, gestures, system events) to simulate real-world use and identify crashes, performance bottlenecks, and responsiveness issues.

This guide shows how to set up and run stress tests using Monkey and interpret results like a pro.

What Is the Android Monkey Tool?

The UI/Application Exerciser Monkey (commonly called Monkey) is a command-line tool included with the Android SDK. It runs on an emulator or device and randomly sends events to test application stability. By simulating a high volume of diverse interactions, Monkey uncovers areas where your app may crash, hang, or fail to respond.

Unlike scripted UI tests, Monkey performs random event generation, which can expose bugs that scripted tests might miss.

Why Stress Test with Monkey?

Stress testing with Monkey helps you:

  • Identify crashes and unhandled exceptions
  • Detect Application Not Responding (ANR) states
  • Expose edge case interactions not covered by manual tests
  • Test how the app behaves under random, high-volume event load

These insights improve release quality, especially for edge cases that real users frequently hit.

Prerequisites

Before you run stress tests:

  1. Android SDK Installed — Ensure SDK tools and adb are available.
  2. Device or Emulator Connected — The target must be accessible through adb.
  3. Package Name of Your App — You’ll specify this when targeting your app.

Running Monkey Stress Test

Open a terminal (Command Prompt / Terminal) and run commands via adb shell to start Monkey from the device/emulator environment.

Basic Monkey Stress Test Command

adb shell monkey -p your.package.name -v 500

Here:

  • adb shell monkey runs Monkey on the device
  • -p your.package.name limits events to your app
  • -v increases verbosity (more output)
  • 500 is the number of random events to send

Monkey will feed random UI events into your app to simulate unpredictable user interactions.

Typical Stress Test Output

During execution, Monkey prints statistics showing:

  • Events sent
  • Unhandled pointers or key drops
  • System and app behavior

For example:

Events injected: 22000
Dropped: keys=15 pointers=126 ...

This indicates how many events were generated and how your app handled them.

Customizing Monkey Test Behavior

Monkey provides many options to tailor the stress test. Some common ones:

OptionPurpose
-s <seed>Repeat event sequence (same random seed)
--throttle <ms>Delay between events to slow injection
--pct-touch <percent>Percentage of touch events
--pct-motion <percent>Percentage of motion (swipe) events
--ignore-crashesContinue despite app crashes
--ignore-timeoutsContinue despite timeouts (ANRs)
--ignore-security-exceptionsContinue despite security errors

Example with throttle and more verbose output:

adb shell monkey -p your.package.name -v --throttle 200 1000

This adds a 200ms delay between events and sends 1000 total events.

Interpreting Test Results

During and after the run, Monkey reports:

  • Unhandled exception stops — indicates code flaws needing fix
  • ANR occurrences — points to UI thread blocking
  • Event drops — possibly due to unsupported interaction types

Analyzing these logs helps prioritize stability improvements before release.

Best Practices for Real-World Use

From extensive Android engineering experience:

  • Use Monkey in CI/CD pipelines to catch regressions early.
  • Run tests with varying event counts (500, 2000, 10000+) across builds.
  • Combine with log capture (adb logcat) to capture stack traces.
  • Pair with other tests (Espresso, UI Automator) for scripted flows.
  • Use option controls to focus on user flows relevant to your app.

Monkey’s randomness exposes unexpected behavior that scripted flows can miss.

Limitations and How to Overcome Them

Monkey is fast and powerful, but:

  • It doesn’t model real user paths — event randomness may not target specific flows.
  • Results can be noisy due to system events being mixed in.
  • It may generate unrealistic sequences that don’t reflect typical use.

To achieve more comprehensive automated UI testing, combine Monkey with structured testing tools like UI Automator or Espresso.

Summary

The Android UI/Application Exerciser Monkey is a lightweight yet effective way to stress-test your application by injecting random user events. With minimal setup via adb shell, you can:

  • Simulate heavy interaction
  • Detect crashes and ANRs
  • Improve app stability and robustness

By tuning event counts, verbosity, and event type distributions, you can craft stress tests tailored to your application’s complexity and risk surfaces.

Visited 4 times, 1 visit(s) today
Close