Android mocks

- [Voiceover] The Android STK provides several mock objects…in the android.test.mock package.…Some of these would be classified as stub or dummy types…under stricter testing terms discussed in this chapter.…The API includes mock objects for…the types you see listed in this table.…These Android types are often needed to be passed…as parameters in a number of Android APIs,…or used to get Android resources,…such as databases, preferences, etc.…The advantage of using these mock objects…is that they come with the Android STK.…

As these are provided by the STK,…simply use the API in your tests.…The mock objects are made part of the test package…along with test classes, instrumentation…code and JUnit code when required.…Calling a method on most of these mock objects…causes an unsupported operation exception to be thrown.…The mock objects are non-functional empty shells.…You need to provide your implementation…for methods your code exercises during testing.…Remember, a mock object is a stand in,…or place holder object for the real object.…

Resume Transcript Auto-Scroll

Author

Released

7/19/2016

Make sure every part of your Android mobile app works perfectly. Test your application at the unit level using unit testing and the built-in tools in the Android SDK. Learn to write the two basic types of unit tests—local and instrumented—and handle complex conditionals, exceptions, and even user interface testing. James P. White introduces tools from within and outside the SDK to speed up and automate unit testing. White also looks at mock objects, which help test code when real objects are unavailable (for example, a yet-to-be-created class). These simple testing techniques will help you create more stable codebases and deliver better quality apps to your end users.