android 结合Junit进行测试.
2014-11-14 00:00
411 查看
学习android. 看看是否可以和 junit一起使用..
修改 AndroidManifest.xml
找到官方的apidemo 发现里面有测试
首先要卸载到原有的 demo 程序.
> adb uninstall com.example.android.apis
测试的过程就也需要重新安装下.
测试结果如下:
啥也没有修改..还是有几个错误的..
总之很方便. 附件是代码..也可以自己从网站下.android-7 版本的.
修改 AndroidManifest.xml
<!-- We add an application tag here just so that we can indicate that this package needs to link against the android.test library, which is needed when building test cases. --> <application> <uses-library android:name="android.test.runner" /> </application> <!-- This declares that this app uses the instrumentation test runner targeting the package of com.example.android.apis. To run the tests use the command: "adb shell am instrument -w com.example.android.apis.tests/android.test.InstrumentationTestRunner" --> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.example.android.apis" android:label="Tests for Api Demos."/>
找到官方的apidemo 发现里面有测试
/* * Copyright (C) 2008 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.example.android.apis; import junit.framework.Test; import junit.framework.TestSuite; import android.test.suitebuilder.TestSuiteBuilder; /** * A test suite containing all tests for ApiDemos. * * To run all suites found in this apk: * $ adb shell am instrument -w \ * com.example.android.apis.tests/android.test.InstrumentationTestRunner * * To run just this suite from the command line: * $ adb shell am instrument -w \ * -e class com.example.android.apis.AllTests \ * com.example.android.apis.tests/android.test.InstrumentationTestRunner * * To run an individual test case, e.g. {@link com.example.android.apis.os.MorseCodeConverterTest}: * $ adb shell am instrument -w \ * -e class com.example.android.apis.os.MorseCodeConverterTest \ * com.example.android.apis.tests/android.test.InstrumentationTestRunner * * To run an individual test, e.g. {@link com.example.android.apis.os.MorseCodeConverterTest#testCharacterS()}: * $ adb shell am instrument -w \ * -e class com.example.android.apis.os.MorseCodeConverterTest#testCharacterS \ * com.example.android.apis.tests/android.test.InstrumentationTestRunner */ public class AllTests extends TestSuite { public static Test suite() { return new TestSuiteBuilder(AllTests.class) .includeAllPackagesUnderHere() .build(); } }
首先要卸载到原有的 demo 程序.
> adb uninstall com.example.android.apis
测试的过程就也需要重新安装下.
[2011-07-14 11:06:25 - ApiDemos] ------------------------------ [2011-07-14 11:06:25 - ApiDemos] Android Launch! [2011-07-14 11:06:25 - ApiDemos] adb is running normally. [2011-07-14 11:06:25 - ApiDemos] Warning: No instrumentation runner found for the launch, using android.test.InstrumentationTestRunner [2011-07-14 11:06:25 - ApiDemos] Performing android.test.InstrumentationTestRunner JUnit launch [2011-07-14 11:06:25 - ApiDemos] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'test_google' [2011-07-14 11:06:25 - ApiDemos] WARNING: Application does not specify an API level requirement! [2011-07-14 11:06:25 - ApiDemos] Device API version is 10 (Android 2.3.4) [2011-07-14 11:06:25 - ApiDemos] Uploading ApiDemos.apk onto device 'emulator-5554' [2011-07-14 11:06:33 - ApiDemos] Installing ApiDemos.apk... [2011-07-14 11:06:42 - ApiDemos] Success! [2011-07-14 11:06:43 - ApiDemos] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 [2011-07-14 11:06:43 - ApiDemos] Collecting test information [2011-07-14 11:06:50 - ApiDemos] Sending test information to Eclipse [2011-07-14 11:06:50 - ApiDemos] Running tests... [2011-07-14 11:06:54 - ApiDemos] Attempting to connect debugger to 'com.example.android.apis' on port 8630 [2011-07-14 11:07:15 - ApiDemos] Test run finished [2011-07-14 11:11:01 - ApiDemos] ------------------------------ [2011-07-14 11:11:01 - ApiDemos] Android Launch! [2011-07-14 11:11:01 - ApiDemos] adb is running normally. [2011-07-14 11:11:01 - ApiDemos] Performing android.test.InstrumentationTestRunner JUnit launch [2011-07-14 11:11:01 - ApiDemos] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'test_google' [2011-07-14 11:11:01 - ApiDemos] WARNING: Application does not specify an API level requirement! [2011-07-14 11:11:01 - ApiDemos] Device API version is 10 (Android 2.3.4) [2011-07-14 11:11:02 - ApiDemos] Application already deployed. No need to reinstall. [2011-07-14 11:11:02 - ApiDemos] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 [2011-07-14 11:11:03 - ApiDemos] Collecting test information [2011-07-14 11:11:05 - ApiDemos] Sending test information to Eclipse [2011-07-14 11:11:05 - ApiDemos] Running tests... [2011-07-14 11:11:08 - ApiDemos] Test run finished [2011-07-14 11:11:33 - ApiDemos] ------------------------------ [2011-07-14 11:11:33 - ApiDemos] Android Launch! [2011-07-14 11:11:33 - ApiDemos] adb is running normally. [2011-07-14 11:11:33 - ApiDemos] Performing android.test.InstrumentationTestRunner JUnit launch [2011-07-14 11:11:33 - ApiDemos] Automatic Target Mode: using existing emulator 'emulator-5554' running compatible AVD 'test_google' [2011-07-14 11:11:33 - ApiDemos] WARNING: Application does not specify an API level requirement! [2011-07-14 11:11:33 - ApiDemos] Device API version is 10 (Android 2.3.4) [2011-07-14 11:11:34 - ApiDemos] Application already deployed. No need to reinstall. [2011-07-14 11:11:34 - ApiDemos] Launching instrumentation android.test.InstrumentationTestRunner on device emulator-5554 [2011-07-14 11:11:35 - ApiDemos] Collecting test information [2011-07-14 11:11:37 - ApiDemos] Sending test information to Eclipse [2011-07-14 11:11:37 - ApiDemos] Running tests... [2011-07-14 11:11:39 - ApiDemos] Test run finished
测试结果如下:
啥也没有修改..还是有几个错误的..
总之很方便. 附件是代码..也可以自己从网站下.android-7 版本的.
相关文章推荐
- android 结合Junit进行测试.
- [Android学习笔记]使用Android Junit进行测试的注意事项
- http://sourceforge.net/projects/easymock/ ant结合junit进行软件自动测试
- Junit4 如何实现并发测试用例,及 Selenium Grid2 与 Junit4 结合进行并发测试。
- ssm练手(CRUD) 2、修改sql方法,并利用JUnit结合数据库进行测试
- 使用Android Junit进行测试的注意事项
- ant结合junit进行软件自动测试(转)
- android 之sqlite 使用及实现增、删、改、查 并使用AndroidTestCase 进行junit 测试
- android jUnit test 进行自动化测试
- android jUnit test 进行自动化测试
- Selenium入门之结合Junit进行自动化测试
- spring结合junit进行单元测试(二)——测试后进行事务回滚
- Hello Android - 进行android junit 测试
- Android 中使用JUnit进行自动测试
- Android 系列 3.4使用Android Studio和JUnit进行测试
- ant结合junit进行软件自动测试
- 无废话Android之android下junit测试框架配置、保存文件到手机内存、android下文件访问的权限、保存文件到SD卡、获取SD卡大小、使用SharedPreferences进行数据存储、使用Pull解析器操作XML文件、android下操作sqlite数据库和事务(2)
- 使用android stdio1.5进行junit测试
- 使用 JUnit 进行容器内测试
- 如何理解、使用Android LogCat以及通过Monkey进行压力测试