Outline• Android Testing Framework• Test Projects• The Testing API• Running Tests• Seeing Test Results
Android Testing Framework (1)• An integral part of the development environment.• Provides architecture and powerful tools help you to test your app at every level from unit to framework.
Android Testing Framework (2)• Key features for the testing framework (1) o Android Test Suites are based on JUnit. Use plain JUnit to test a class doesnt call the Android API. Use Androids JUnit extensions to test Android components. o Android JUnit extensions provide component-specific test classes. Helper methods for creating mock objects. Helper methods for controlling the lifecycle of a component. o Test suites are contained in test packages that are similar to a main application packages. You dont to learn a new set of tools or techniques for designing and building tests.
Android Testing Framework (3)• Key features for the testing framework (2) o The SDK tools for building and tests are available in Eclipse with ADT, and also in command-line form for use with other IDES. These tools get information from the project of the application under test and use this information to automatically create the build files, manifest file and the directory structure for the test package. o The SDK also provides monkeyrunner, a API testing devices with Python programs. UI/Application Exerciser Monkey, a command-line tool for stress-testing UIs by sending pseudo-random events to a device.
Test Projects (1)• Test, like Android applications, are organized into projects. test project usually bundles with tested project
Test Projects (2)• Two ways to create your test project o Using ADT An eclipse plugin will generate files automatically. o Using command-line tools It will create Ant build files you need automatically.
Test Projects (3)• Use Android tools to create test project having the following benefits: o Set up your test project to use the InstrumentationTestRunner as the test case runner. o Create appropriate package name for the test project. o Automatically create the proper build files. Manifest files and directory structure for the test project. Helps you to build the test project without having to modify build files and sets up the linkage between test package and the application under test.
The Testing API (1)• Provided by JUnit. o TestCase Class To do unit testing on a class that doesnt call Android APIs. Offers setup, and teardown methods. o JUnit Assertion Class Compare values you expect from a test to the actual results and throw an exception if the comparison fails. Display the test results.• Provided by Android. o AndroidTestCase Class A subclass of TestCase in JUnit. Offers Android-specific setup, teardown, and helper methods. o Android Assertion Class A subclass of Junit Assertion class.
The Testing API (2)• Provided by Android. o Instrumentation A set of control methods or "hooks" in the Android system. These hooks control an Android component independently of its normal lifecycle. Use instrumentation to invoke the activitys lifecycle callback directly. o InstrumentationTestCase A subclass of JUnits TestCase Class. The class can access the instance of instrumentation directly.
The Testing API (3)• Provided by Android. o ApplicationTestCase Its useful to verify that the <application> elements in the manifest file is correctly set up. o Component-specific test cases Activity Testing Service Testing Content Provider Testing Android doesnt provide a separate test case for BroadcastReceiver. Instead, test a BroadcastReceiver by testing the component that sends it intent object, to verify that the BroadcastReceiver responds correctly.
The Testing API (4)• Provided by Android. o Mock object classes o Context for testing