Touch, hold, swipe, release gesture simulation in Android Unit test

 There are a lot of various frameworks which are provide you with a very useful methods for writing unit tests for Android applications. But when you need something specific almost everything you have to do it yourself.

For example, simple actions sequence: touch screen, hold finger few seconds and slide it slowly to the random side of screen, release. Such simple gesture can’t be reproduced by any testing framework, including cool Robotium so far.

I have simulated this gesture using a simple approach – sending touch events to the Android OS manually:

Off course you are welcome to remove hard coded coords with you own coords logic. The main trick here is to simulate ‘hold’ by simple string:

You are able to combine pauses and moves to reproduce any single touch gesture! 🙂