zoukankan      html  css  js  c++  java
  • Android——单元测试




    在实际开发中,开发android软件的过程需要不断地进行测试。而使用Junit测试框架,侧是正规的Android开发的必用技术,在Junit中可以得到组件,可以模拟发送事件和检测程序处理的正确性。
    第一步:首先在AndroidManifest.xml中加入下面红色代码:
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="cn.itcast.action“ android:versionCode="1“  android:versionName="1.0">
     <application android:icon="@drawable/icon" android:label="@string/app_name">
            <uses-library android:name="android.test.runner" />
            ....
     </application>
     <uses-sdk android:minSdkVersion="6" />
     <instrumentation android:name="android.test.InstrumentationTestRunner"
      android:targetPackage="cn.itcast.action" android:label="Tests for My App" />
    </manifest>
    上面targetPackage指定的包要和应用的package相同。
    第二步:编写单元测试代码(选择要测试的方法,右键点击Run As--Android Junit Test ):
    import android.test.AndroidTestCase;
    import android.util.Log;
    public class XMLTest extends AndroidTestCase {
     public void testSomething() throws Throwable {
    Assert.assertTrue(1 + 1 == 3);
     }
    }
    l

    版权声明:本文为博主原创文章,未经博主允许不得转载。

  • 相关阅读:
    linux 常用命令
    git 常见命令
    合并两个有序链表---python
    Code Contract for .NET
    Kruskal最小生成树算法
    逻辑-哲学
    停机问题
    逆向工程
    .net framework
    python 类库
  • 原文地址:https://www.cnblogs.com/blogs-chao/p/4764907.html
Copyright © 2011-2022 走看看