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