android:label="Test for my app"/ 編寫 單元測試代碼 :必須繼承自Android Te" name="description" />

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 如何對Android系統手機進行單元測試

    發表于:2011-01-25來源:作者:點擊數: 標簽:手機Windows PhonSelenium;驗收測
    如何對Android系統手機進行 單元測試 如何進行Android單元測試 Menifest.xml中加入: 中加入: 外面加入: MI SSION android:name="android.permission.RUN_INSTRUMENTATION" /> android:label="Test for my app"/ 編寫 單元測試代碼 :必須繼承自Android Te

    如何對Android系統手機進行單元測試  

     如何進行Android單元測試

      Menifest.xml中加入:

      中加入:

      

      外面加入:

      MISSION android:name="android.permission.RUN_INSTRUMENTATION" />

      

      android:label="Test for my app"/>

      編寫單元測試代碼:必須繼承自AndroidTestCase

      package name.feisky.android.test;

      import android.test.AndroidTestCase;

      import junit.framework.Assert;

      public class MyTest extends AndroidTestCase {

      private static final String Tag="MyTest";

      public void testSave() throws Throwable

      {

      int i=4+8;

      Assert.assertEquals(5,i);

      }

      public void testSomethingElse() throws Throwable {

      Assert.assertTrue(1 + 1 == 12);

      }

      }

      執行測試

      IntelliJ中:

      eclipse中:右鍵 run as Android JUnit Test

      命令行工具:

      adb shell am instrument -w name.feisky.android.test/android.test.InstrumentationTestRunner

      也可以新建一個測試項目進行測試

      New > Project > Android > Android Test Project.

      添加測試用例

      添加新類,基類設置為android.test.ActivityInstrumentationTestCase2

      添加構造函數

      添加setUp()方法,這個方法在所有的測試之前進行變量和測試環境的初始化。

      @Override

      protected void setUp() throws Exception {

      super.setUp();

      mActivity = this.getActivity();

      mView = (TextView) mActivity.findViewById(com.example.helloandroid.R.id.textview);

      resourceString = mActivity.getString(com.example.helloandroid.R.string.hello);

      }

      添加testPreconditions()方法,檢查初始化環境,只執行一次

      public void testPreconditions() {

      assertNotNull(mView);

      }

      添加單元測試

      public void testText() {

      assertEquals(resourceString,(String)mView.getText());

      }

      測試 Run As... > Android JUnit Test

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>