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