Android中如何使用JUnit进行单元测试 eclipse
Android中如何使用JUnit进行单元测试
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.junittest" android:label="@string/app_name"
></instrumentation>
|
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.junittest"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="18" />
<instrumentation android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.example.junittest" android:label="@string/app_name"
></instrumentation>
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<uses-library android:name="android.test.runner"/>
<activity
android:name="com.example.junittest.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>
</application>
</manifest>
|
package com.example.junittest;
public class Calculator {
public int add(int x,int y){
return x+y;
}
public int sub(int x,int y){
return x-y;
}
public int divide(int x,int y){
return x/y;
}
public int multiply(int x,int y){
return x*y;
}
}
|

package com.example.test;
import junit.framework.Assert;
import com.example.junittest.Calculator;
import android.test.AndroidTestCase;
import android.util.Log;
public class CalculatorTester extends AndroidTestCase {
private static final String TAG = CalculatorTester.class.getSimpleName();
private Calculator calculator;
/**
* This method is invoked before any of the test methods in the class.
* Use it to set up the environment for the test (the test fixture. You can use setUp() to instantiate a new Intent with the action ACTION_MAIN. You can then use this intent to start the Activity under test.
*/
@Override
protected void setUp() throws Exception {
Log.e(TAG, "setUp");
calculator = new Calculator();
super.setUp();
}
/**
* 测试Calculator的add(int x, int y)方法
* 把异常抛给测试框架
* @throws Exception
*/
public void testAdd() throws Exception{
int result = calculator.add(3, 5);
Assert.assertEquals(8, result);
}
/**
* 测试Calculator的divide(int x, int y)方法
* 把异常抛给测试框架
* @throws Exception
*/
public void testDivide() throws Exception{
int result = calculator.divide(10, 0);
Assert.assertEquals(10, result);
}
/**
* This method is invoked after all the test methods in the class.
* Use it to do garbage collection and to reset the test fixture.
*/
@Override
protected void tearDown() throws Exception {
Log.e(TAG, "tearDown");
calculator = null;
super.tearDown();
}
}
|




Android中如何使用JUnit进行单元测试 eclipse的更多相关文章
- Android之如何使用JUnit进行单元测试
转的:http://www.blogjava.net/qileilove/archive/2014/05/19/413824.html Android中如何使用JUnit进行单元测试 在我们日常开发a ...
- SpringBoot重点详解--使用Junit进行单元测试
目录 添加依赖与配置 ApplicationContext测试 Environment测试 MockBean测试 Controller测试 情况一 情况二 方法一 方法二 本文将对在Springboo ...
- 在Android中进行单元测试遇到的问题
问题1.Cannot connect to VM socket closed 在使用JUnit进行测试的时候,遇到这个问题.网上的解释是:使用Eclipse对Java代码进行调试,无论是远程JVM还 ...
- 软件工程第二次作业(Android Studio利用Junit进行单元测试)
一.开发工具的安装和运行 1.安装 由于我的电脑之前就安装好了Android Studio,就不再重装了.在这里就给出几条安装过程中需要注意的地方吧: 安装包最好在官网下载已经带有Android SD ...
- Android使用JUnit进行单元测试
前言:为什么要进行单元测试?单元测试能快速是开发者,找到代码中的问题所在,因为是单元测试,所以代码只执行响应的测试单元,执行快解决问题的效率高,同时提高代码的质量. Android中的单元测试可简单分 ...
- Android中使用自身携带的Junit新建一个测试工程
1.新建立一个Android工程 package com.shellway.junit; public class Service { public int divide(int a,int b){ ...
- 如何将Android默认的Camra程序导入到eclipse中
由于工作需要将camera源码导入到Eclipse中,找了很多的方法,现将自己的整理发出来.... 由于开发的要求,需要将Android默认的Camra程序导入到eclipse中,进行修改和再开发. ...
- Android中的单元测试
2015年5月19日 23:10 在Android中,已经内置了Junit所以不需要在导包.只要继承AndroidTestCase类就可以了. 首先需要修改AndroidManifes ...
- Android 开发之开发插件使用:Eclipse 插件 SQLiteManger eclipse中查看数据内容--翻译
最近研究了一段时间Android开发后发现,google自带的ADT工具,缺失一些开发常用的东西,希望可以构建一个类似使用JAVA EE开发体系一样开发的工具包集合,包括前台开发,调试,到后台数据库的 ...
随机推荐
- 从IC设计业看中国企业之发展
从IC设计业看中国企业之发展 在半导体领域,国际平均毛利润水平为40%.去年IC设计年会中,中国半导体行业协会IC设计分会理事长魏少军指出,中国IC设计业平均毛利润水平比国际平均水平低了12.39 ...
- 2016湘潭邀请赛—Heartstone
http://202.197.224.59/OnlineJudge2/index.php/Problem/read/id/1246 题意: 有n只怪,每只怪有指定的HP.现在1和2两种攻击方式,前者扣 ...
- mapply
相比 lapply( )和 sapply( )在一个向量上迭代,mapply( )可以在多个向量上进行迭代.换句话,mapply 是 sapply 的多元版本:mapply(function(a, b ...
- ffmpeg_资料_01
1. 用ffmpeg制作推流工具,实现推流系统声音和桌面到rtmp服务器-CSDN论坛-CSDN.NET-中国最大的IT技术社区.html http://bbs.csdn.net/topics/392 ...
- [原][osgearth]osgearthElvation中的一帧
create tile key contains 获取tile上的临界值 这里先获取层数的切份(下图) 然后使用xmin,xmax,ymin,ymax获取tile的四个点 再通过geoextent获取 ...
- 【 Python】模块学习之Flask模板引擎:jinja2
原文链接:https://www.cnblogs.com/dachenzi/p/8242713.html 模板的概念 要了解jinja2,那么需要先理解模板的概念.模板在Python的web开发中广泛 ...
- Java Spring-JdbcTemplate增删改查
2017-11-11 21:13:13 Spring 框架中提供了对持久层技术支持的类 : JDBC : org.springframework.jdbc.core.support.JdbcDaoSu ...
- MySQL查询in操作排序
in操作排序 先说解决方案: select * from test where id in(3,1,5) order by field(id,3,1,5); 或许有人会注意过,但我以前真不知道 SQL ...
- MQ选型对比RabbitMQ RocketMQ ActiveMQ Kafka
几种MQ产品说明: ZeroMQ : 扩展性好,开发比较灵活,采用C语言实现,实际上他只是一个socket库的重新封装,如果我们做为消息队列使用,需要开发大量的代码 RabbitMQ :结合erla ...
- IOS-线程(GCD)
一.GCD的使用 // // IBController3.m // IBCoder1 // // Created by Bowen on 2018/4/25. // Copyright © 2018年 ...