Android Unit Test Androidtestcase

Source: Internet
Author: User


In real-world development, the process of developing Android software requires constant testing. Instead of using the JUnit test framework, it is a must-have technology for regular Android development, which can be used in junit to simulate the correctness of sending events and detecting program processing.

For example, if you want to validate a method in a custom class, you can create the class object in the unit test and invoke the class method given the appropriate parameters.


The specific methods of Android unit testing are as follows:

(1). Create a class that inherits Androidtestcase, which is a unit test class.

(2). Declare the instrumentation branch in Androidmainfest. (Introduction of the Unit test library into this project)

(3). Declare <uses-library/> branch in <application >.

(4). Double-click the method name in Androidtestcase, and right-select Runas--android JUnit Test to run the method.


public class Androidtestcasedemo extends androidtestcase {

private static final String TAG = "Android JUnit Test";

public void Test1 ()

{

LOG.D (TAG, "test1 Run");

}

public void Test2 ()

{

LOG.D (TAG, "test2 run");

}


}



<?xml version= "1.0" encoding= "Utf-8"?>

<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"

Package= "Com.test.androidtestcasedemo"

Android:versioncode= "1"

Android:versionname= "1.0" >


<uses-sdk

Android:minsdkversion= "8"

Android:targetsdkversion= "/>"

<!--introducing Unit test Libraries--

<instrumentation

<!--name: fixed---

Android:name= "Android.test.InstrumentationTestRunner"

<!--Targepackage is the package name of the unit test class--

Android:targetpackage= "Com.test.androidtestcasedemo" >

</instrumentation>


<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= ". Mainactivity "

Android:label= "@string/app_name" >

<intent-filter>

<action android:name= "Android.intent.action.MAIN"/>


<category android:name= "Android.intent.category.LAUNCHER"/>

</intent-filter>

</activity>

</application>


</manifest>


This article is from the "whatever957" blog, make sure to keep this source http://whatever957.blog.51cto.com/6835003/1705959

Android Unit Test Androidtestcase

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.