Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint
Share this Page URL
Help

Chapter 13. Testing and instrumentation > Pulling strings: Android instrumentat...

13.2. Pulling strings: Android instrumentation

So far we’ve been testing the invisible parts of your application, those parts that may play a fundamental role, but aren’t seen by the user. AndroidTestCase is sufficient for that: services, content providers, and the application object are background objects, so we don’t need any support for simulating a user interacting with them. But what about activities? We have plenty of user interface interaction here: users click buttons, type text, rotate the screen, scroll lists, and so on. How would we do all that as part of an automated test?

Android’s answer to this is instrumentation. Instead of calling methods and manipulating objects in the scope of an Activity, we take one step back and control the Activity itself; we orchestrate or instrument it. When writing normal application code, you’re confined to the internal interfaces of objects such as activities or services, and you can only react to outside system events in a passive way, for instance via lifecycle hooks such as onCreate or keyboard listeners like onKeyDown. There’s no way to manipulate anything from outside, to take control yourself. Instrumentation means breaking out of that restriction and being able to control activities and services from the outside. Think of puppets on strings: Instrumentation pulls the strings!


  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial