Android Learning Note: Unit Testing for Android apps

Source: Internet
Author: User

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

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

<manifest xmlns:android= "Http://schemas.android.com/apk/res/android" Package= "COM.PCCW"Android:versioncode= "1"Android:versionname= "1.0" > <uses-sdk android:minsdkversion= "8"/> <application android:icon= "@drawable/icon" android:label= "@string/app_name" > <activity android:name= ". Mainactivity "Android:label= "@string/app_name" > <intent-filter> <action android:name= "Android.intent.action.MAI N "/> <category android:name=" Android.intent.category.LAUNCHER "/> &LT;/INTENT-FILTER&G        T </activity> <!-Add code 1--> <uses-library android:name= "Android.test.runner"/></application > <!-Add code 2--> <instrumentation android:name= "Android.test.InstrumentationTestRunner"Android:targetpackage= "COM.PCCW" android:label= "AAA"/></manifest>

1. <uses-library android:name= "Android.test.runner"/> representative to bring in some of the dependent libraries in the Unit testing framework

2. <instrumentation android:name= "Android.test.InstrumentationTestRunner" android:targetpackage= "COM.PCCW" Android Oid:label= "AAA"/> Represents the start-up unit of the Configuration Unit test framework, there are several classes of start-up devices, you can choose, generally we use the above.

3. Targetpackage is the same as the package above, which represents the unit test framework and the current application is in the same process

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

 Public class Personservice {        publicvoid  Save (String name) {        = name.substring (6);    }          Public int Add (intint  b) {        return a +B;    }}

Step three: Write the unit test code

 Public classPersonservicetestextendsAndroidtestcase { Public voidTestsave ()throwsException {personservice service=NewPersonservice (); Service.save (NULL); }         Public voidTestadd ()throwsException {personservice service=NewPersonservice (); intresult = Service.add (1, 2); Assert.assertequals (3, result); }}

Android Learning Note: Unit Testing for Android apps

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.