EclipseADT编写单元测试代码的步骤

1. 写一个类 extends AndroidTestCase
2. 写一个测试方法
   a.必须是public 
   b.必须抛出异常给操作系统            

 public void textAdd()throws Exception {
            CalService calService = new CalService();
            int result = calService.add(1, 1);
            //3. 对测试方法的结果断言
            assertEquals(2, result);
  }

3. 对测试方法的结果断言    

 assertEquals(2, result);

4. 在清单文件中配置   

在manifest标签:
 <instrumentation
     android:name="android.test.InstrumentationTestRunner"
     android:targetPackage="com.example.juint" >
 </instrumentation>    
在Application标签里:
 <uses-library android:name="android.test.runner" />

5. 选中测试方法,右键运行,Android Junit Test
    * 绿条 测试成功
    * 红条 测试失败

原文地址:https://www.cnblogs.com/loaderman/p/6430696.html