One: The basic concept of testing
According to the Source:
Black Box testing: Focus on process and results
White box test: Write test method According to the source code
The granularity of the test:
Method Test: Function test
Unit Tested: Unit test
Integration testing:
Depending on the number
Smoke test
Pressure test
Two: Build your own test framework
1. Business code
Public class Calcservice {
Public int Add (int x,int y) {
return x+y;
}
}
2. Test code
Public class Testcalcservice extends androidtestcase {
Public void Testadd ()throws exception{
Calcservice service=New calcservice ();
int Sum=service.add (3, 5);
assertequals (8, sum);
}
}
3. Build a Test framework
<?xml version= "1.0" encoding= "Utf-8"?>
<manifest xmlns:android= "Http://schemas.android.com/apk/res/android"
package= "COM.EXAMPLE.ANDROID3"
Android:versioncode= "1"
Android:versionname= "1.0" >
<!-- the instruction set needs to be mainfest node under -
<instrumentation
Android:name= "Android.test.InstrumentationTestRunner"
android:targetpackage= "COM.EXAMPLE.ANDROID3"
/>
<uses-sdk
Android:minsdkversion= "8"
Android:targetsdkversion= "/>"
<application
Android:allowbackup= "true"
android:icon= "@drawable/ic_launcher"
Android:label= "@string/app_name"
Android:theme= "@style/apptheme" >
<!-- in the Application using function libraries under nodes -
<uses-libraryandroid:name= "Android.test.runner"/>
<activity
Android:name= "Com.example.android3.MainActivity"
Android:label= "@string/app_name" >
<intent-filter>
<actionandroid:name= "Android.intent.action.MAIN"/>
<categoryandroid:name= "Android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
</application>
</manifest>
Three: New test project
Four: Log information of the test
Verbose: Reminders
Debug: Debugging
Info: Info
Warn: Warning
Error: Wrong
1. Modify the business code above
public class Calcservice {
Privatestring tag= "Calcservice";
Publicint Add (int x,int y) {
LOG.V (Tag, "x=" +x);
LOG.D (Tag, "y=" +y);
int result=x+y;
LOG.I (Tag, "result=" +result);
LOG.W (Tag, "result=" +result);
LOG.E (Tag, "result=" +result);
Returnx+y;
}
}
2. Add a test filter
1. Run the test code
The log file shows:
Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21
Android Basics (6): JUnit test