android里面做单元测试
第一,JUnit。
      实用范围:
     

东西,比如业务逻辑,数据封装,数值计算等等。并不能测试android api。


第二, 采用Instrumentation. Android单元测试的主入口是InstrumentationTestRunner。它相当于

JUnit当中TestRunner的作用。你可以将 Instrumentation理解为一种没有图形界面的,具有启动能力

的,用于监控其他类(用Target Package声明)的工具类。任何想成为Instrumentation的类必须继承

android.app.Instrumentation。


第一种测试方式实现步骤:
   setup 1:   选中测试项目点右键
   setup 2:   在Run Configuration里新建一个JUnit。
   setup 3:  

            ->add Library)
   setup 4:  


第二种测试方式步骤:

setup1: 在manifest配置文件中加入蓝色部份


<?xml version="1.0" encoding="utf-8"?>
 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="your.tests.package">
     <application>
        <uses-library android:name="android.test.runner" />
    </application>
    <instrumentation android:name="android.test.InstrumentationTestRunner"
                     android:targetPackage="your.work.package"
                     </manifest>
setup2: 注意红色部份package.如果不好区别可用最上层包名.如:package="your"
setup3: 写测试类
public class SdcardTest extends AndroidTestCase {
  public void test1(){
   File f=new File("/sdcard");
   String[] l=f.list();
   this.assertTrue(f.exists());
   this.assertTrue(f.isDirectory());
   this.assertTrue(f.list().length>0);
  }
 }