首页 文章 精选 留言 我的

精选列表

搜索[单元测试],共2968篇文章
优秀的个人博客,低调大师

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; importandroid.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,可能是我前面打开了这个目录,结果就随意打开了它修改了它。希望大家以后小心行事。 最新内容请见作者的GitHub页:http://qaseven.github.io/

优秀的个人博客,低调大师

Android开发中的单元测试

1、测试类一定要extendsAndroidTestCase 类 2、测试方法要以test开头,并抛出异常 3、在测试方法中new出要测试的类,然后对应其功能进行测试 (经常会用到Assert.assertEquals(a,b);) package com.zhy.junitExample.test; import com.zhy.servers.server; import android.test.AndroidTestCase; public class serverTest extends AndroidTestCase { public void testsave() throws Exception{ server ser = new server(); ser.save(); } } 4、在AndroidMainfest中要添加 <uses-library android:name="android.test.runner" /> 加入测试库 <instrumentation android:name="android.test.InstrumentationTestRunner" android:targetPackage="com.zhy.junitExample" /> 注意android:targetPackage是你要测试的类的项目中的Package(打开其AndroidMainfest,即可看到),不是项目中具体的包名。 5、green is YES,red is NO! 本文转自老Zhan博客园博客,原文链接:http://www.cnblogs.com/mybkn/archive/2012/04/13/2445852.html,如需转载请自行联系原作者

资源下载

更多资源
Nacos

Nacos

Nacos /nɑ:kəʊs/ 是 Dynamic Naming and Configuration Service 的首字母简称,一个易于构建 AI Agent 应用的动态服务发现、配置管理和AI智能体管理平台。Nacos 致力于帮助您发现、配置和管理微服务及AI智能体应用。Nacos 提供了一组简单易用的特性集,帮助您快速实现动态服务发现、服务配置、服务元数据、流量管理。Nacos 帮助您更敏捷和容易地构建、交付和管理微服务平台。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Sublime Text

Sublime Text

Sublime Text具有漂亮的用户界面和强大的功能,例如代码缩略图,Python的插件,代码段等。还可自定义键绑定,菜单和工具栏。Sublime Text 的主要功能包括:拼写检查,书签,完整的 Python API , Goto 功能,即时项目切换,多选择,多窗口等等。Sublime Text 是一个跨平台的编辑器,同时支持Windows、Linux、Mac OS X等操作系统。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册