Learning Android™ Application Programming: A Hands-On Guide to Building Android Applications
by James Talbot, Justin McLean, Jorge Hernandez
Creating a Mock Application
The TimerActivity class assumes that the application is the OnYourBike class, and not the MockApplication class. This makes perfect sense, except that when you’re testing an activity, it doesn’t use the real application; instead, it uses a fake or mock application and so an exception will occur. Most of the methods of the MockApplication class do not work and will throw an exception if you call them, unless you provide your own versions. This makes your activity much easier to test, because you can specify exactly how it interacts with the application.
You can fix this error by creating an interface containing all the required application methods and then creating a class that implements those methods and using that ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access