The unit test of android is very easy to use. It can detect whether your function classes or methods are correct without relying on complicated operations.
Unit Test Configuration:
1. The unit test class inherits AndroidTestCase
2. Add AndroidManifest. xml file
<Uses-library android: name = "android. test. runner"> </uses-library>
<Instrumentation
Android: name = "android. test. InstrumentationTestRunner"
Android: targetPackage = "com. luku. log" // your package name
Android: label = "Test for my app"
> </Instrumentation>
3. Compile the test class
Example:
[Java]
Import android. test. AndroidTestCase;
Import android. util. Log;
Public class test extends AndroidTestCase
{
Public void add () throws Exception
{
Int I = 1 + 1;
Xxx ();
Log. I ("test", "result =" + I );
}
Public String xxx ()
{
String str = "output ";
Int I = 1;
Int x = 2;
Int c = I + x;
Str = str + c;
Return str;
}
}
Import android. test. AndroidTestCase;
Import android. util. Log;
Public class test extends AndroidTestCase
{
Public void add () throws Exception
{
Int I = 1 + 1;
Xxx ();
Log. I ("test", "result =" + I );
}
Public String xxx ()
{
String str = "output ";
Int I = 1;
Int x = 2;
Int c = I + x;
Str = str + c;
Return str;
}
}
[Java]
<? Xml version = "1.0" encoding = "UTF-8"?>
<Manifest xmlns: android = "http://schemas.android.com/apk/res/android"
Package = "com. luku. log"
Android: versionCode = "1"
Android: versionName = "1.0" type = "codeph" text = "/codeph">
<Uses-sdk android: minSdkVersion = "8"/>
<Application android: icon = "@ drawable/icon" android: label = "@ string/app_name">
<Uses-library android: name = "android. test. runner"> </uses-library>
<Activity android: name = ". LogActivity"
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>
<Instrumentation
Android: name = "android. test. InstrumentationTestRunner"
Android: targetPackage = "com. luku. log"
Android: label = "Test for my app"
> </Instrumentation>
</Manifest>
From running snails