Sunday, November 7, 2010

TouchUtils.clickView too slow!?

Here's the scenario...
  • You have written an android test-suite for your application.
  • Your test cases use 'TouchUtils.clickView' class by android, in order to simulate clicking the buttons on your view.
  • However, time between each click is slow to the extent that it has become the bottleneck in your test-suite! 
In the implementation of TouchUtils.clickView, there's a sleep of 1000ms (1sec) after every call made to this function. This is the reason for the delay you've been seeing.
 So, I went ahead and copied the code for 'clickView' and created my own class for providing users with programmable delays. This would help the verification guys to fine tune the delays between each clicks. Hence, trying to keep the runtime of the test-suite under control.
 This class 'MyTouchUtils' can be found here. Just save this file to your project and 'import' this class into your test files. Then, if you want to simulate a click event with 200ms of delay after the click, just do the following:MyTouchUtils.myClickView(this, view, 200);
 Of course there's a trade-off involved between the time given for your program to settle down, digest your click event and produce the results; and the total runtime of your test-suite. So, you have to make the decision accordingly.

Happy Coding!

No comments:

Post a Comment