zoukankan      html  css  js  c++  java
  • Android:使用单元测试

    一、加入配置项:

    1、在Application项内,Activity项外加入“引用测试类库”代码:

    <uses-library android:name="android.test.runner" />

    2、在Application项同级加入“测试入口”代码:

    <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.juniux.junittest" android:label="Test My App" />
    <!--android:label属性可忽略-->

    二、编辑测试类:

    注:该类需继承 AndroidTestCase 类,建议命名为:"要测试的类名"+Test;测试方法命名:Test+"要测试的方法名",且throws异常。

    package com.juniux.test;
    import junit.framework.Assert;
    import com.juniux.services.PersonService;
    import android.test.AndroidTestCase;
    public class PersonServiceTest extends AndroidTestCase {
        public void TestSave() throws Exception {
            PersonService service = new PersonService();
            service.Save(null);
        }
        public void TestAdd() throws Exception
        {
                PersonService service = new PersonService();
                int result = service.Add(1, 2);            
                Assert.assertEquals(3, result);        
        }
    }

    三:启用测试

    在Outline列表中右键点击要测试的方法,并选择 RunAs -> Android JUnit Test 启动测试。

  • 相关阅读:
    P1535 游荡的奶牛
    rmq
    bsgs算法详解
    P1396 营救
    P1547 Out of Hay
    P1474 货币系统 Money Systems
    P1209 [USACO1.3]修理牛棚 Barn Repair
    P1208 [USACO1.3]混合牛奶 Mixing Milk
    P1108 低价购买
    android屏幕适配的全攻略--支持不同的屏幕尺寸适配平板和手机
  • 原文地址:https://www.cnblogs.com/cxmsky/p/3746977.html
Copyright © 2011-2022 走看看