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

来源:互联网 发布:淘宝重复铺货怎么处罚 编辑:程序博客网 时间:2024/06/06 03:07

http://blog.csdn.net/shandong_chu/article/details/25787423


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


1、前提条件

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

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


2、使用StringBuffer来自定义方法StringBufferDemo(String url, String str)
[java] view plaincopy
  1. public void StringBufferDemo(String url, String str) throws IOException{  
  2.        File file=new File(url);  
  3.        if(!file.exists())  
  4.            file.createNewFile();  
  5.        FileOutputStream out=new FileOutputStream(file,true);          
  6.         
  7.            StringBuffer sb=new StringBuffer();  
  8.            sb.append(str); //直接在文件中追加文字  
  9.            out.write(sb.toString().getBytes("utf-8"));  
  10.                 
  11.        out.close();  
  12.    }  

变量:

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) ;
0 0
原创粉丝点击