iis服务器助手广告广告
返回顶部
首页 > 资讯 > 移动开发 >Android:单元测试Junit的配置
  • 391
分享到

Android:单元测试Junit的配置

单元junitAndroid 2022-06-06 12:06:21 391人浏览 独家记忆
摘要

  在实际开发中,开发Android软件的过程需要不断地进行测试。而使用Junit测试框架,侧是正规Android开发的必用技术,在Junit中可以得到组件,可以模拟发送事

  在实际开发中,开发Android软件的过程需要不断地进行测试。而使用Junit测试框架,侧是正规Android开发的必用技术,在Junit中可以得到组件,可以模拟发送事件和检测程序处理的正确性..........

  第一步:首先在AndroidManifest.xml中加入下面代码:

<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android=Http://schemas.android.com/apk/res/android package="hb.learn.junit" android:versionCode="1" android:versionName="1.0"> <uses-sdk android:minSdkVersion="8" /> <application android:icon="@drawable/icon" android:label="@string/app_name">

<!-- 在本应用中导入需要使用的包,放在application里面activity外面 --> <uses-library android:name="android.test.runner" />

<activity android:name=".JunitTestActivity" android:label="@string/app_name"> <intent-filter> <action android:name="android.intent.action.MaiN" /> <cateGory android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity>

</application>

<!-- 记住这个一要放在application外面,不然会出现配置错误 信息 --> <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="hb.learn.junit" android:label="Tests for My App" /> </manifest>

  上面targetPackage指定的包要和应用的package相同。是这个测试类所在的包名;

  第二步:编写单元测试代码(选择要测试的方法,右键点击“Run As”--“Android Junit Test” ):

import android.test.AndroidTestCase; import android.util.Log; public class XMLTest extends AndroidTestCase { public void testSomething() throws Throwable { Assert.assertTrue(1 + 1 == 3); } }


--结束END--

本文标题: Android:单元测试Junit的配置

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

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

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

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

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

  • 微信公众号

  • 商务合作