灯火互联
管理员
管理员
  • 注册日期2011-07-27
  • 发帖数41778
  • QQ
  • 火币41290枚
  • 粉丝1086
  • 关注100
  • 终身成就奖
  • 最爱沙发
  • 忠实会员
  • 灌水天才奖
  • 贴图大师奖
  • 原创先锋奖
  • 特殊贡献奖
  • 宣传大使奖
  • 优秀斑竹奖
  • 社区明星
阅读:3467回复:0

android学习笔记5--------业务bean(单元测试) .

楼主#
更多 发布于:2012-09-06 13:44


Android的单元测试非常好用,它可以检测你的功能类或方法是否正确,而不依赖于一些复杂的操作。
单元测试配置:
1.单元测试类继承AndroidTestCase
2.AndroidManifest.xml文件添加
<uses-library Android:name="Android.test.runner"></uses-library>
<instrumentation
     Android:name="Android.test.InstrumentationTestRunner"
     Android:targetPackage="com.luku.log"//你的包名
     Android:label="Test for my app"
    ></instrumentation>
3.测试类编写
例子:
[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", "结果是="+i);
    }
    
    public String xxx()
    {
        String str="输出";
        
        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", "结果是="+i);
}

public String xxx()
{
  String str="输出";
  
  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">
    <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>


摘自 奔跑的蜗牛


喜欢0 评分0
游客

返回顶部