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.