robotium测试工具使用之——输出log日志

     本文主要使用Java对文件操作功能,来实现测试中log内容的输出


1、前提条件

在被测试的应用中添加对SD卡的读写权限,文件为AndroidManifest.xml,添加以下标示

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" ></uses-permission>


2、 使用StringBuffer来自定义方法StringBufferDemo(String url, String str)

	public void StringBufferDemo(String url, String str) throws IOException{
        File file=new File(url);
        if(!file.exists())
            file.createNewFile();
        FileOutputStream out=new FileOutputStream(file,true);        
       
            StringBuffer sb=new StringBuffer();
            sb.append(str); //直接在文件中追加文字
            out.write(sb.toString().getBytes("utf-8"));
               
        out.close();
    }

变量:

url:指定生成的log文件, 例如:url = "/sdcard/sms.log"

str:需要输出的log信息, 例如:str= "test" 

直接在testcase中调用该方法即可

String log_url = "/sdcard/sms.log" ;
String log_text = "test" ;

StringBufferDemo(log_url,log_text) ;

你可能感兴趣的:(robotium测试工具使用之——输出log日志)