Android Learning Series-unit test and program debugging (5)

Source: Internet
Author: User

Android Learning Series-unit test andProgramDebugging (5)
1. Key Points
1) The following nodes must be configured in androidmanifest. xml:
<Uses-library Android: Name = "android. Test. Runner"/>

<Instrumentation Android: Name = "android. Test. instrumentationtestrunner"

Android: targetpackage = "cn. nt. Test" Android: Label = "Test for MyApp"/>

2) androidmanifest. xml completeCode
<? XML version = "1.0" encoding = "UTF-8"?>

<Manifest xmlns: Android = "http://schemas.android.com/apk/res/android"

Package = "cn. nt. test"

Android: versioncode = "1"

Android: versionname = "1.0" type = "codeph" text = "/codeph">

<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. Main"/>

<Category Android: Name = "android. Intent. Category. launcher"/>

</Intent-filter>

</Activity>

 

<Uses-library Android: Name = "android. Test. Runner"/>

</Application>

<Uses-SDK Android: minsdkversion = "8"/>

<Instrumentation Android: Name = "android. Test. instrumentationtestrunner"

Android: targetpackage = "cn. nt. Test" Android: Label = "Test for MyApp"/>


3) The unit test class must inherit from androidtestcase.
example: public class logtest extends androidtestcase {
Public void testsave () throws exception {
personservice service = new personservice ();
service. save (null);
}

Public void testadd () throws exception {
Personservice service = new personservice ();
Int actual = service. Add (1, 2 );
Assert. assertequals (8, actual); // the test result is displayed in the unit test window.
}

}

2. program debugging output information
Private Static final string tag = "logtest ";
 
Public void testoutlog () throws throwable {
Log. I (TAG, "www.baidu.cn ");
}
 
Public void testoutlog5 () throws throwable {
Log. I (TAG, "123456 ");
}
 
Public void testoutlog2 () throws throwable {
System. Out. println ("www.csdn.com ");
}
 
Public void testoutlog3 () throws throwable {
System. Err. println ("www.163.com ");
}
The output information is displayed in the logcat window.
Information classification level debug <info <warn <error.

 

Related Article

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.