分享

Android 对应用进行单元测试

 leomuyi 2014-01-08

AndroidManifest.xml
  1. <?xml version="1.0" encoding="utf-8"?>  
  2.   
  3. <manifest xmlns:android="http://schemas./apk/res/android"  
  4.   
  5.     package="org.soai.app"  
  6.   
  7.     android:versionCode="1"  
  8.   
  9.     android:versionName="1.0" >  
  10.   
  11.   
  12.     <uses-sdk android:minSdkVersion="8" />  
  13.   
  14.   
  15.     <application  
  16.   
  17.         android:icon="@drawable/ic_launcher"  
  18.   
  19.         android:label="@string/app_name" >  
  20.   
  21.         <activity  
  22.   
  23.             android:label="@string/app_name"  
  24.   
  25.             android:name=".MainActivity" >  
  26.   
  27.             <intent-filter >  
  28.   
  29.                 <action android:name="android.intent.action.MAIN" />  
  30.   
  31.   
  32.                 <category android:name="android.intent.category.LAUNCHER" />  
  33.   
  34.             </intent-filter>  
  35.   
  36.         </activity>  
  37.   
  38.           
  39.   
  40.         <uses-library android:name="android.test.runner"/>  
  41.   
  42.     </application>  
  43.   
  44.  <instrumentation android:name="android.text.InstrumentationTestRunner"  
  45.   
  46.  android:targetPackage="org.soai.app" android:label="Tests for My app"/>  
  47.   
  48. </manifest>  

 测试类:需要继承AndroidTestCase类

  1. public class FileServiceTest extends AndroidTestCase {  
  2.   
  3.      private static final String TAG = "FileServiceTest";  
  4.   
  5.      public void testRead() throws Throwable{  
  6.   
  7.      FileService service = new FileService(this.getContext());  
  8.   
  9.      String result = service.read("test.txt");  
  10.   
  11.      Log.i(TAG, result);  
  12.   
  13.      }   
  14.   
  15. }  


  

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章