Android study Note 5 -------- business bean (unit test ).

Source: Internet
Author: User

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


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.