qileilove

          blog已經轉移至github,大家請訪問 http://qaseven.github.io/

          Eclipse中Android單元測試

            說說正常的代碼吧
            1)
            1:java測試
          <span style="font-size:14px;">package com.medivh.app;
          public class Person
          {
          public String sub(String username)
          {
          String sub = username.substring(3);
          return sub;
          }
          public int add(int a,int b)
          {
          return a+b;
          }
          }</span>
            2:
          <span style="font-size:14px;">package com.medivh.app;
          import org.junit.Test;
          import junit.framework.Assert;
          import android.test.AndroidTestCase;
          public class PersonTest extends AndroidTestCase
          {
          @Test
          public void testSub() throws Exception
          {
          Person p = new Person();
          p.sub(null);
          }
          public void testAdd() throws Exception
          {
          Person p = new Person();
          int result = p.add(1, 4);
          Assert.assertEquals(result, 6);
          }
          }
          </span>
           2)AndroidManifest.xml
          <span style="font-size:14px;"><?xml version="1.0" encoding="utf-8"?>
          <manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.medivh.app"
          android:versionCode="1"
          android:versionName="1.0">
          <application android:icon="@drawable/ic_launcher" android:label="@string/app_name">
          <activity android:name=".MainActivity"
          android:label="@string/app_name">
          <intent-filter>
          <action android:name="android.intent.action.MAIN" />
          <category android:name="android.intent.category.LAUNCHER" />
          </intent-filter>
          </activity>
          <span style="color:#FF0000;"><uses-library android:name="android.test.runner" /></span>
          </application>
          <uses-sdk android:minSdkVersion="8" />
          <span style="color:#FF0000;"><instrumentation android:name="android.test.InstrumentationTestRunner"
          android:targetPackage="com.medivh.app" android:label="Tests for My App" /></span>
          </manifest> </span>
            3)測試
            右鍵項目Run as.. Android Junit Test 就會出結果
            開始的時候犯迷糊結果各種出錯:
            No instrumentation runner found for the launch, using android.test.InstrumentationTestRunner
            First does not specify a android.test.InstrumentationTestRunner instrumentation or does not declare uses-library android.test.runner in its AndroidManifest.xml
            is not configured correctly for running tests
            到網上各種查,發現配置沒錯啊。最后才發現問題出在我居然眼睛進沙子一般修改了bin下面的AndroidManifest.xml,可能是我前面打開了這個目錄,結果就隨意打開了它修改了它。希望大家以后小心行事。

          posted on 2014-06-30 18:38 順其自然EVO 閱讀(976) 評論(0)  編輯  收藏 所屬分類: android

          <2014年6月>
          25262728293031
          1234567
          891011121314
          15161718192021
          22232425262728
          293012345

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 巴林左旗| 镇江市| 平远县| 罗江县| 济南市| 阿克苏市| 郴州市| 观塘区| 宝山区| 顺昌县| 内乡县| 老河口市| 博爱县| 耒阳市| 宁津县| 慈利县| 兰西县| 屯留县| 盐津县| 思茅市| 凤翔县| 岳阳县| 武乡县| 万州区| 曲周县| 湾仔区| 灵川县| 长治市| 图木舒克市| 宁晋县| 洛扎县| 大连市| 久治县| 彰武县| 始兴县| 昂仁县| 永德县| 三都| 东乡| 东光县| 吉木乃县|