TouchUtils and ActivityInstrumentationTestCase2 user event Unit test case not working <p>Currently I am struggling a little with the Unit test framework...</p> <p><strong>what I am trying to do</strong></p> <ul> <li>I need to simulate 2 clicks on the screen (100,100) and (400,400) at a small duration difference.</li> <li>I need to simulate a longPressClick on the screen Let's say ( 200, 200 )</li> <li>Upon User click the native code runs and performs pixel manipulation on Bitmap.</li> <li>This test is going to run for multiple pair-sets of points, for analysing the runtime performance of the system</li> </ul> <p><strong>Here's where I am stuck</strong></p> <ul> <li>I am using activityInstrumentationTestCase2 and touchUtils for the user click events.</li> <li>TouchUtils.longClickView(InstrumentationTestCase test, View v) works fine ; I'm able to detect the long pressing event propely , But test-case finishes even before the calculation / rendering is complete in my UI thread ; how do I stop the test from exiting in this case ?</li> <li>How do i simulate 2 / 3 user clicks @ particular location on screen ? cause TouchUtils.clickView(InstrumentationTestCase test, View v) would only simulate the user click in the center of the screen ... How to do it properly ?</li> </ul> <p><strong>These are the things I have tried and seems I'm missing out something:</strong></p> <ul> <li>TouchUtils.longClickView(InstrumentationTestCase test, View v) works fine...for creating longClickView .. Even I was able to create longClickView() at particular screen location by introducing the timedelay between ACTION_DOWN and ACTION_UP event.. please refer to the code attached </li> <li>I was able to achieve the user clicking event at particular screen location , But I faced a strange issue .. When I am displatching the MotionEvent(100,100) from the test-case.. The framework would always add "-76" in the Y event .. not sure why there was this deviation ... I worked around the issue by adding 76 to my input data (100,176) for time being .. did anyone face a similar issue ? </li> <li>Even seems with this approach timing is very critical .. as If i place more delay between ACTION_DOWN and ACTION_UP , the event is detected as longClickPress ... and if I put a little less ... the "second" single click events ( ACTION_DOWN + ACTION_UP ) gets detected as DoubleTapEvent .. </li> </ul> <p>What should be the right timing combination for ACTION_UP and ACTION_DOWN .. for a single user click event simulation .. ????????</p> <pre><code> @Test public void testClick(){ List&lt;Points&gt; pointSequence = new ArrayList&lt;Points&gt;(); Log.d(TAG, "FirClick Start Timing : " + SystemClock.uptimeMillis()); pointSequence.add(new Points(100f,176f)); pointSequence.add(new Points(100f,176f)); singleClickSimulation(pointSequence,false); } private void singleClickSimulation(List&lt;Points&gt; pointSequence, Boolean addDelay) { long downTime = SystemClock.uptimeMillis(); long eventTime = SystemClock.uptimeMillis(); // NOTE : If I do not place this then the event is detected as doubleTap. eventTime += 100; Instrumentation inst = getInstrumentation(); MotionEvent event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_DOWN, pointSequence.get(0).getX(), pointSequence.get(0).getY(), 0); inst.sendPointerSync(event); //eventTime = SystemClock.uptimeMillis(); pointSequence.remove(0); //This delay I have added just to test; whether there is enough time for pixel manipulation or not, actually it would be used only at the end of the run of all the test cases for single user click if(addDelay){ eventTime = SystemClock.uptimeMillis() + 3000; } eventTime += 25; event = MotionEvent.obtain(downTime, eventTime, MotionEvent.ACTION_UP, pointSequence.get(0).getX(), pointSequence.get(0).getY(), 0); inst.sendPointerSync(event); pointSequence.remove(0); } </code></pre>