广告
返回顶部
首页 > 资讯 > 移动开发 >Android搭建Junit测环境
  • 410
分享到

Android搭建Junit测环境

环境junitAndroid 2022-06-06 13:06:40 410人浏览 独家记忆
摘要

  在AndroidManifest.xml文件中增加两个东西,分别是:   1、uses-library ,位于application里面。   2、instrume

  在AndroidManifest.xml文件中增加两个东西,分别是:   1、uses-library ,位于application里面。   2、instrumentation,与application同级。   完整的AndroidManifest.xml文件如下: 1 <?xml version="1.0" encoding="utf-8"?> 2 <manifest xmlns:android="Http://schemas.android.com/apk/res/android" 3       package="com.lzb.study.db" 4       android:versionCode="1" 5       android:versionName="1.0"> 6     <application android:icon="@drawable/icon" android:label="@string/app_name"> 7         <!-- 单元测试 --> 8         <uses-library android:name="android.test.runner" /> 9         <activity android:name=".DBActivity" 10                   android:label="@string/app_name"> 11             <intent-filter> 12                 <action android:name="android.intent.action.MaiN" /> 13                 <cateGory android:name="android.intent.category.LAUNCHER" /> 14             </intent-filter> 15         </activity> 16 17     </application> 18 19     <!-- 启动测试器 --> 20     <instrumentation android:name="android.test.InstrumentationTestRunner" 21         android:targetPackage="com.lzb.study.db" android:label = "Tests for My App" /> 22 23 </manifest>   然后,建立测试类。测试类中的测试方法必须以test开头。 1 public class PersonServiceTest extends AndroidTestCase { 2 3     public void testSave() throws Exception { 4         PersonService ps = new PersonService(this.getContext()); 5         Person person = new Person(); 6         person.setName("李刚"); 7         person.setAge((short)0); 8         ps.save(person); 9 10     } 11 }   然后在test类中,选中testcase,点击右键,选择Run As --> Android Junit Test,开始执行case。


--结束END--

本文标题: Android搭建Junit测环境

本文链接: https://www.lsjlt.com/news/28836.html(转载时请注明来源链接)

有问题或投稿请发送至: 邮箱/279061341@qq.com    QQ/279061341

本篇文章演示代码以及资料文档资料下载

下载Word文档到电脑,方便收藏和打印~

下载Word文档
猜你喜欢
软考高级职称资格查询
编程网,编程工程师的家园,是目前国内优秀的开源技术社区之一,形成了由开源软件库、代码分享、资讯、协作翻译、讨论区和博客等几大频道内容,为IT开发者提供了一个发现、使用、并交流开源技术的平台。
  • 官方手机版

  • 微信公众号

  • 商务合作