Android Review Test in Android

Source: Internet
Author: User


There are two types of tests in Android:

First, write the test code in a project.

Second, to create a new project to write test code.


First, write the test code in a project

Steps:

1. Write a class inheritance Androidtestcase

Such as:

Package Com.example.junittest;import Junit.framework.assert;import Android.test.androidtestcase;public class MyTest Extends Androidtestcase {public void Testdevide () {Service service = new service (); System.out.println (Service.devide (2));/** * Assert.assertequals (expected, actual); * Function: Assertion. * Expected: Expectation * Actual: Actual value */assert.assertequals (5, Service.devide (10, 2));} public void TestDevide1 () {Service service = new Service (); System.out.println (Service.devide (10, 2));}}


2. Configure the following two-segment code in Androidmanifest.xml.

<instrumentation
Android:name= "Android.test.InstrumentationTestRunner"
Android:targetpackage= "Com.njupt.sqlit"/>

<uses-library android:name= "Android.test.runner"/>


Such as:

<?xml version= "1.0" encoding= "Utf-8"? ><manifest xmlns:android= "http://schemas.android.com/apk/res/        Android "package=" Com.example.junittest "android:versioncode=" 1 "android:versionname=" 1.0 "> <uses-sdk android:minsdkversion= "8" android:targetsdkversion= "/> <instrumentation android:name=" and        Roid.test.InstrumentationTestRunner "android:targetpackage=" Com.example.junittest "/> <application        Android:allowbackup= "true" android:icon= "@drawable/ic_launcher" android:label= "@string/app_name"                Android:theme= "@style/apptheme" > <uses-library android:name= "Android.test.runner"/> <activity android:name= "com.example.junittest.MainActivity" android:label= "@string/app_name" &            Gt <intent-filter> <action android:name= "Android.intent.action.MAIN"/> <categor Y android:name= "Android.Intent.category.LAUNCHER "/> </intent-filter> </activity> </application></man Ifest>

Parsing the targetpackage in:<insrtumentation/> specifies the registration of the app that needs to be tested. That is to say also <manifest/> node in the package

The content specified by the label remains the same.


It is important to note that:

1. Right-click on the test class-----"Run as Android JUNIT test", this time all the test methods of this test class run.

2. Right-click on the test method-----"Run as Android JUNIT test". Only one test method is run at this time.


Second, a new test project specifically



Method:

CTRL + N--------->> you will see the following interface:


Then select Android Test Project-----


Enter the name of the Android test project here ... -------------》


Select the project to be tested here. ---------------------------------------》

Then click Next to continue .....


2, and in a project to write the difference between the test code.

1) No mainactivity in the new test project

2) Androidmanifest.xml has its own <instrument/> and other labels

3) It is necessary to put the test project with the north side of the project are sent to the mobile phone




SOURCE Download:

http://download.csdn.net/detail/caihongshijie6/7612085
















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.