Android Unit Test

Source: Internet
Author: User

http://blog.csdn.net/duancanmeng/article/details/7458851

The first step: Add the following two code to the Androidmanifest.xml:

Code one <uses-library android:name= "Android.test.runner"/> Represents a dependency library in a third party

Code two <instrumentation android:name= "Android.test.InstrumentationTestRunner"

Android:targetpackage= "COM.PCCW" Android:label = "AAA"/> Represents the start-up device for the configuration unit test framework, there are several classes of starter units, which are generally chosen, Targetpackage is the current package name, representing the unit test framework in the same process as the project

  

Step Two: Write the business logic, the module that needs to be tested

What does this mean??????

This is a class that defines two public methods

Step three: Write the unit test code

Inherited?

Throw an exception?

New last object, calling method

Fourth step: Open the Outline window in Eclipse, which shows all the methods of the Unit test class

Then you want to test which method, the right mouse button on which test method, select Run as, and then select Android JUnit Test, if there are exceptions or errors, the following occurs:

If it is normal, the following will be the case:

Http://blog.chinaunix.net/uid-20355083-id-1963965.html

If you want to do unit testing in Android, there are three ways to do this.

First, JUnit is the most familiar and common junit of Java programmers,

Second, Instrumentation,instrumentationtestrunner, using instrumentation. The main entrance to the Android unit test is Instrumentationtestrunner.

Third, Androidtestcase, using Android-provided androidtestcase, to implement its own test case by inheriting this class, and then design the UI for Test itself, which is used in another blog, You can click on the link below to read:

The first part

Part II

Here's an example of how to do unit testing with instrumentation.

Step 1. First write the activity you want to test:

Step 2.

Next write the test class, The main test is the Add () method. we are in the current code directory, in a new folder, named Test, and inside the new package com.android.ut.test. Then add a new class to the inside. as follows:

Step 3. The final step is to change the Manifest file.

Step 4. Run

Actually, it's normal.

Android Unit Test

Related Article

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.