Tim
Tim

Reputation: 5767

Send a long click (or any touch event) to a View in ActivityInstrumentationTestCase2

When doing unit testing in Android activities using ActivityInstrumentationTestCase you could use TouchUtils to "send" a long click to a view in the activity with longClickView (ActivityInstrumentationTestCase test, View v)

ActivityInstrumentationTestCase was deprecated in favour of ActivityInstrumentationTestCase2. So the longClickView is no longer available; it is deprecated and recommends using ActivityInstrumentationTestCase2 "which provides more options for configuring the Activity under test"

I cannot find how to do this operation (sending a touch event to a view) in ActivityInstrumentationTestCase2. Can anyone show me an example of how to do this now?

EDIT

Further addition to the question. Is there anyway I can get the test to wait on a textview being updated. I have a button which fetches something from the network and displays it in a TextView. I'd like to test pressing that button and then examining the resulting text.

EDIT 2

I'm sorry for continuing to add to this question but they are related. So...when I press that button I expect the vibrator to vibrate. Is there an accepted was to confirm that this has occurred?

Upvotes: 2

Views: 2978

Answers (1)

Tim
Tim

Reputation: 5767

I just found this in SO.

Is this the recommended way to go? To call the performLongClick() and performClick() methods on the buttons directly?

Upvotes: 3

Related Questions