Android builds JUnit test environment

Source: Internet
Author: User

Add two items to the Androidmanifest.xml file, respectively:

1, Uses-library, located in the application inside.

2, instrumentation, and application peers.

The complete Androidmanifest.xml file is as follows:

1<?xml version= "1.0" encoding= "Utf-8"?>2<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"3        Package= "Com.lzb.study.db"4Android:versioncode= "1"5Android:versionname= "1.0" >6<application android:icon= "@drawable/icon" android:label= "@string/app_name" >7<!--unit Test--8<uses-library android:name= "Android.test.runner"/>9<activity android:name= ". Dbactivity "TenAndroid:label= "@string/app_name" > One<intent-filter> A<action android:name= "Android.intent.action.MAIN"/> -<category android:name= "Android.intent.category.LAUNCHER"/> -</intent-filter> the</activity> -  -</application> -  +<!--start the tester-- -<instrumentation android:name= "Android.test.InstrumentationTestRunner" +Android:targetpackage= "com.lzb.study.db" Android:label = "Tests for My App"/> A  at</manifest>

Then, build the test class. The test method in the test class must begin with testing.

1  Public classPersonservicetestextendsAndroidtestcase {2     3      Public voidTestsave ()throwsException {4Personservice PS =NewPersonservice ( This. GetContext ());5Person person =NewPerson ();6Person.setname ("Li Gang");7Person.setage (( Short) 0);8 Ps.save (person);9         Ten     } One}

Then, in the Test class, select TestCase, right-click, select Run as--and Android Junit Test to start the case.

Android builds JUnit test environment

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.