编写Android工程里测试代码的步骤

第一步: 写个类去继承 AndroidTestCase

public class TestStudent extends AndroidTestCase

并且编写一个测试的方法,

注意,测试的方法必须是 public void , 并且方法不能够接收任何的参数信息

1 public void testInsert(){
2 }

第二步: 在清单文件中添加 使用到的指令集 ,以及 使用到 的类库

  <!-- 通过包命来指定要测试的目标 应用程序  -->
    <instrumentation
        android:name="android.test.InstrumentationTestRunner"
        android:targetPackage="com.why.studentsystem" >
 </instrumentation>

并且还需要在 application 元素下,添加 uses-library
<!-- 使用到 这个 类库  -->
       <uses-library android:name="android.test.runner"/>

第三步:  运行测试方法 (右键Run As  Android Junit Test)

public void testAdd(){}
原文地址:https://www.cnblogs.com/wanghaoyuhappy/p/5252530.html