Android Testing Point

Source: Internet
Author: User

The test application demonstrates these key points:

  • An Android test is itself a Android application that's linked to the application under test by entries in its AndroidManifest.xml file .
  • An Android test itself is an Android application that is linked to the application by the project under test in Androidmanifest.xml, which explains two questions: The test itself is also an app for Android;
  • Instead of Android components, a Android test application contains one or more test cases. Each of the these is a separate class definition.
  • An Android test application consists of one or more test sets used in place of the Android module. Each is a separate class definition.
  • Android test Case Classes Extend the JUnit TestCase class.
  • The test set for Android inherits from JUnitTestCase类.
  • Android test Case Classes-activities extend JUnit and also connect to the application under test with Instrumentat Ion. You can send keystroke or touch events directly to the UI.
  • The test class for activities inherits from JUnit and also enables you to use instrumentation under the test set. You can manipulate the UI directly via input and touch events.
  • You choose a Android test case class based on the type of component (application, activity, content provider, or service) You are testing.
  • You can choose to conduct your tests on the basis of a component (application, activity, content provider, or service).
  • Additional test tools in Eclipse/adt provide integrated support for creating test applications, running them, and viewing The results.
  • In addition, tools in Eclipse/adt can support the creation of test applications, run tests and view the results of the integration suite

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.
  • Test with initial conditions. Test the application correctly under test initialization. This is also a unit test of an applied onCreate() method. The test initial conditions also include a possible measure to be provided in 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 can automate UI tests by sending key events from the test application to the main application.
  • UI testing. Test the main UI that can be properly manipulated. This test mainly shows the usability of the instrumentation feature in the activity test. It shows how you can automate UI testing by sending major events from your test app to your primary application.
  • State management tests. Test the application ' s code for saving state. This test demonstrates the instrumentation features of the Test Runner, which is available for testing any component.
  • Affirm the management test set. Test your app's code in order to save the state. This test shows the instrumentation function of Test Runner, which can be used for testing any component.

The next step is to define the test case class. In this tutorial, you'll be creating a test case class that includes:

    • Test Setup. This use of the JUnit setUp() method demonstrates some for the tasks you might perform before running an Android test.
      • getActivity(). Gets a reference to the activity under test ( SpinnerActivity ). This call also starts the activity if it's not already running.
      • findViewById(int). Gets a reference to the Spinner widget of the application under test.
      • getAdapter(). Gets a reference to the adapter (an array of strings) backing the spinner.

ADD This code SpinnerActivityTest to the definition of, after the constructor definition:

@Override
Protected voidSetUp() Throws Exception {
Super.SetUp();

Setactivityinitialtouchmode(False);

Mactivity=Getactivity();

Mspinner=
(Spinner Mactivity. (
        Com. Android. Example. Spinner. R. Id. Spinner01
     
      mplanetdata = Mspinner.getadapter ();
  } //end of SetUp () method definition
    • testing initial conditions. This test demonstrates a good testing technique. It also demonstrates that with Android instrumentation your can look at the application under test  before &nbs P;the main activity starts. The test checks that the application ' s important objects has been initialized. If The test fails, you then know, and then tests against the application is unreliable, since the application was RU Nning in a incorrect state.

      Note:  the purpose of testing initial Conditions is not the same as using  setUp () . The junit  setUp ()  runs once before each test method , and its purpose are to create a Clean test environment. The initial conditions test runs once, and its purpose are to verify that the application under test are ready for be tested.

The initial conditions test verifies, the application under test is initialized correctly. It is a illustration of the types of tests you can run, so it's not comprehensive. It verifies the following:

    • The item select Listener is initialized. This listener was called when a selection was made from the spinner.
    • The adapter that provides values to the spinner is initialized.
    • The adapter contains the right number of entries.

The actual initialization of the application under test setUp() is do in, which the Test runner calls automatically before Every Test. The verifications is done with JUnit Assert calls. As a useful convention, the method name is testPreConditions() :

Public voidTestpreconditions() {
Asserttrue(mspinner. Getonitemselectedlistener() = null);
Asserttrue(mplanetdata! = null);
Assertequals(mplanetdata. GetCount(),adapter_count);
} //End of testpreconditions () method definition

ADD This member:

Publicstaticfinalint=9;     
    • Testing the UI. This test shows how to control the main application ' s UI with instrumentation, a powerful automation feature of Android TE Sting.
    • Testing state management. This test shows some techniques for testing how well the application maintains state in the Android environment. Remember, provide a satisfactory user experience, your application must never lose its current state, even if it ' s Interrupted by a phone call or destroyed because of memory constraints. The Android activity lifecycle provides ways to maintain state, and the SpinnerActivity application uses them. The test shows the techniques for verifying this they work.

Android Testing Point

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.