Activity Testing Tutorial. Docand Developer tools
ಜಾಹಿರಾತು
ಜಾಹಿರಾತು
Activity Testing Tutorial
37. Activity Testing Tutorial
Content from developer.android.com/tools/testing/activity_test.html through their Creative Commons Attribution 2.5 license
Android includes powerful tools for testing applications. The tools extend JUnit with additional features, provide convenience classes for mock Android system objects, and use instrumentation to give you control over your main application while you are testing it. The entire
Android testing environment is discussed in the document Testing Fundamentals.
This tutorial demonstrates the Android testing tools by presenting a simple Android application and then leading you step-by-step through the creation of a test application for it. The test application demonstrates these key points:
In this section
• Prerequisites
• Installing the Tutorial Sample Code
• Setting Up the Emulator
• Setting Up the Projects
• Creating the Test Case Class
• Adding the test case class file
• Adding the test case constructor
• Adding the setup method
• Adding an initial conditions test
• An Android test is itself an Android application that is linked to the application under test by entries in its
AndroidManifest.xml
file.
• Instead of Android components, an
Android test application contains one or more test cases. Each of these is a separate class definition.
• Adding a UI test
• Adding state management tests
• Running the Tests and Seeing the Results
• Forcing Some Tests to Fail
• Next Steps
Appendix
• Android test case classes extend the
JUnit TestCase class.
• Android test case classes for activities extend JUnit and also connect you to the application under test with instrumentation. You can send keystroke or touch events directly to the UI.
• Installing the Completed Test Application
File
• For Users Not Developing In Eclipse
See Also
• Testing Fundamentals
• You choose an Android test case class based on the type of component
(application, activity, content provider, or service) you are testing.
• ActivityInstrumentationTestCase2
• Assert
• InstrumentationTestRunner
• Additional test tools in Eclipse/ADT provide integrated support for creating test applications, running them, and viewing the results.
The test application contains methods that perform the following tests:
• Initial conditions test. Tests that the application under test initializes correctly. This is also a unit test of the application's onCreate() method. Testing initial conditions also provides a confidence measure for subsequent tests.
• UI test. Tests that the main UI operation works correctly. This test demonstrates the instrumentation features available in activity testing. It shows that you can automate UI tests by sending key events from the test application to the main application.
• State management tests. Test the application's code for saving state. This test demonstrates the instrumentation features of the test runner, which are available for testing any component.
205
Content from developer.android.com/tools/testing/activity_test.html through their Creative Commons Attribution 2.5 license
ಡೌನ್ಲೋಡ್ ಮಾಡಿ
ಜಾಹಿರಾತು