qileilove

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

          Android Studio下執行單元測試

           今天在Android Studio下學習怎么執行單元測試,現總結如下:
            1. https://coderwall.com/p/ybds4w
            http://blog.futurice.com/android_unit_testing_in_ides_and_ci_environments
            2. 出現問題如下:
          Exception in thread "main" java.lang.NoClassDefFoundError: junit/textui/ResultPrinter
          at java.lang.Class.forName0(Native Method)
          at java.lang.Class.forName(Class.java:169)
          at com.intellij.rt.execution.application.AppMain.main(AppMain.java:113)
          Caused by: java.lang.ClassNotFoundException: junit.textui.ResultPrinter
          at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
          at java.security.AccessController.doPrivileged(Native Method)
          at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
          at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
          at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
          at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
          ... 3 more
            原因為調用的junit  android-studio\plugins\junit\lib\junit-rt.jar 下沒有junit/textui/ResultPrinter 這個class文件,怎么解決呢????
            3. com.google.inject的maven配置 
          <dependency>
          <groupId>com.google.inject</groupId>
          <artifactId>guice</artifactId>
          <version>1.0</version>
          </dependency>
            4. android-4.0.1.2.jar Maven配置
          <dependency>
          <groupId>com.google.android</groupId>
          <artifactId>android</artifactId>
          <version>4.0.1.2</version>
          </dependency>
            5. 用gradle編譯項目時出錯:
            Could not create plugin of type 'AppPlugin'
            解決方法:
            classpath 'com.android.tools.build:gradle:0.7.0' 改為 classpath 'com.android.tools.build:gradle:0.7.3'
            6. 用gradle 同步工程出現錯誤如下:
            Unable to load class 'org.gradle.api.artifacts.result.ResolvedComponentResult'
            解決方法:
            classpath 'com.android.tools.build:gradle:0.7.3'
           7. gradle-plugin and the gradle version說明:
          There is a relation between gradle-plugin and the gradle version. For example
          com.android.tools.build:gradle:0.6.+  -> gradle 1.8
          com.android.tools.build:gradle:0.7.+  -> gradle 1.9
          com.android.tools.build:gradle:0.8.+  -> gradle 1.9/1.10
          com.android.tools.build:gradle:0.9.+  -> gradle 1.10/1.11
          You can find gradle version used in your project in the file gradle/wrapper/gradle-wrapper.properties
          Also there is a relation between gradle-plugin and the IDE version. For example:
          Android Studio 0.3.x -> gradle-plugin 0.6
          Android Studio 0.4.x -> gradle-plugin 0.7
          Android Studio 0.4.3+ -> gradle-plugin 0.8
          Android Studio 0.5.x  -> gradle-plugin 0.9
          For updated news you can check this link: http://tools.android.com/recent
            8. 錯誤問題如下:
          !!! JUnit version 3.8 or later expected:
          java.lang.RuntimeException: Stub!
          at junit.runner.BaseTestRunner.<init>(BaseTestRunner.java:5)
          at junit.textui.TestRunner.<init>(TestRunner.java:54)
          at junit.textui.TestRunner.<init>(TestRunner.java:48)
          at junit.textui.TestRunner.<init>(TestRunner.java:41)
          解決方法:(https://github.com/robolectric/deckard-gradle)
          For Intellij, go to Project Structure -> Modules -> deckard-gradle pane. In the Dependencies tab, move the Module SDK dependency (i.e. Android API 19 Platform) to be the last item in the list.
          For Android Studio, dependency ordering is currently not modifiable via any GUI. Therefore, you must modify the project iml file directly as such and reload the project:
          <orderEntry type="library" exported="" scope="TEST" name="wagon-provider-api-1.0-beta-6" level="project" />
          <orderEntry type="library" exported="" scope="TEST" name="xercesMinimal-1.9.6.2" level="project" />
          <orderEntry type="jdk" jdkName="Android API 19 Platform" jdkType="Android SDK" />
          <---make sure this is the last orderEntry
          </component>
          </module>
            9.下載android sdk和platform API參考地址:
            http://xtbbbbdx.blog.51cto.com/3506227/1009209
            android-3.0_r02-linux.zip的下載鏈接
            http://dl.google.com/android/repository/android-3.0_r02-linux.zip
            10:  NoClassDefFoundError: com/intellij/rt/execution/junit/JUnitStarter: com/intellij/rt/execution/junit/JUnitStarter
            解決方法:???
            11. No resource found that matches the given name 'Theme.AppCompat.Light.DarkActionBar'.
            解決方法:
            using android-support-v7-appcompat.jar lib inside libs folder
            (compile'com.android.support:appcompat-v7:19.0.+')

          posted on 2014-04-29 10:49 順其自然EVO 閱讀(6834) 評論(0)  編輯  收藏 所屬分類: android

          <2014年4月>
          303112345
          6789101112
          13141516171819
          20212223242526
          27282930123
          45678910

          導航

          統計

          常用鏈接

          留言簿(55)

          隨筆分類

          隨筆檔案

          文章分類

          文章檔案

          搜索

          最新評論

          閱讀排行榜

          評論排行榜

          主站蜘蛛池模板: 诸暨市| 康乐县| 门头沟区| 高雄市| 利辛县| 辽阳县| 察隅县| 渝中区| 武川县| 建阳市| 台江县| 托克托县| 盐城市| 德庆县| 黔江区| 万州区| 天柱县| 常宁市| 东明县| 依兰县| 靖江市| 克拉玛依市| 桃源县| 吉林省| 中超| 南丹县| 梁山县| 高尔夫| 石阡县| 建宁县| 湾仔区| 秭归县| 鲜城| 菏泽市| 白玉县| 乐东| 镇江市| 崇阳县| 永仁县| 尼勒克县| 平果县|