Android:使用Junit测试框架

    xiaoxiao2021-11-30  24

    一、在AndroidManifest.xml中application标签内加入下面代码: <uses-library android:name="android.test.runner" />                 //引入test的library <instrumentation             android:name="android.test.InstrumentationTestRunner"   //系统API             android:label="TestApp"                                 //名称             android:targetPackage="com.g.im.Test" />                //测试类 二、写单元测试代码: import junit.framework.Assert; import android.test.AndroidTestCase; public class TestApp extends AndroidTestCase {     public void testSave() throws Throwable {         //测试代码,比如保存数据到DB中,测试保存方法有无异常。     } }

    三、执行测试:

    打开Outline视图,右击要测试的方法,在弹出菜单中选择“Run As”--“Android Junit Test”。

    转载请注明原文地址: https://ju.6miu.com/read-679029.html

    最新回复(0)