Android Test和Logcat

一 测试相关概念

是否有源码

  黑盒测试: 测试工具

  白盒测试: 对所有的源码特别熟悉 对特定的代码进行测试 都是编程

时间

  单元测试(程序员)

  模块测试

  集成测试

  系统测试

  回归测试(改bug) 

压力

  猴子测试

  冒烟测试

 

二 Junit单元测试

<!-- 第一步: 在AndroidManifest.xml中加入下面代码: 在<manifest>节点下 -->
<instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="应用程序的包名"></instrumentation>
     
<!-- 第二步: 在AndroidManifest.xml中加入下面代码: 在<application>节点下 -->
<uses-library android:name="android.test.runner"/>
//第三步: java代码
public class 类名Test extends AndroidTestCase {
    //单元测试
    public void test方法名() throws Exception{
        //测试的类对象
        PersonService ps = new PersonService();
        //使用方法
        ps.getFirstName();
    }
    //断言测试
    public void test方法名() throws Exception{
        //测试的类对象
        PersonService ps = new PersonService();
        //使用方法
        int actual = ps.add(1, 1);
        //断言测试
        Assert.assertEquals(2, actual);
    }
}

第四步

进入测试类中 选择方法右击: run as --> android junit test

 

三 Logcat

android应用程序中打印日志

一般开发中使用自己的Logcat打印 可控制

/**
 * Log工具类
 * @author huangyi
 */
public final class MyLog {
    private final static boolean FLAG = true;//测试      
    
    public static void v(String tag,String msg){
        if(FLAG){
            Log.v(tag, msg);
        }
    }    
    public static void d(String tag,String msg){
        if(FLAG){
            Log.d(tag, msg);
        }
    }
    public static void i(String tag,String msg){
        if(FLAG){
            Log.i(tag, msg);
        }
    }
    public static void w(String tag,String msg){
        if(FLAG){
            Log.w(tag, msg);
        }
    }
    public static void e(String tag,String msg){
        if(FLAG){
            Log.e(tag, msg);
        }
    }
}
原文地址:https://www.cnblogs.com/huangyi-427/p/4636159.html