package com.itheima.junit;

import android.os.Bundle;
import android.app.Activity;
import android.view.Menu; public class MainActivity extends Activity { @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
} @Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
} }
package com.itheima.junit.test;

import com.itheima.junit.utils.Utils;

import android.test.AndroidTestCase;
//黑盒测试(不懂代码)
//白盒测试(懂代码)
public class TestCase extends AndroidTestCase {
//#单元测试junit(测试功能不用启动整个项目) public void test(){//不是重写的方法,鼠标右键就可以跑起来了。
int result = Utils.add(3, 5);
//断言:用来检测实际值与期望值是否一致
//断言的作用,检测运行结果和预期是否一致
//如果应用出现异常,会抛给测试框架
assertEquals(8, result);//8是期望值,result是实际值。
} public void test2(){
Utils.chuyi(2, 1);
}
}
package com.itheima.junit.utils;

public class Utils {

    public static int add(int i, int j){
return i + j;
} public static void chuyi(int i, int j){
int result = i / j;
}
}
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.itheima.junit"
android:versionCode="1"
android:versionName="1.0" > <uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="17" />
* 在指定指令集时,targetPackage指定你要测试的应用的包名
<instrumentation
android:name="android.test.InstrumentationTestRunner"
android:targetPackage="com.itheima.junit" 项目的包名,就是上面的manifest的package="com.itheima.junit"
></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.itheima.junit.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>

android 68 单元测试的更多相关文章

  1. Android Studio单元测试入门

    Android Studio单元测试入门 通常在开发Android app的时候经常会写一些小函数并验证它是否运行正确,通常做法我们是把这个函数放到某个界面(Activity上)执行一下,运行整个工程 ...

  2. Android之单元测试学习

    1.单元测试概念 单元测试(又称为模块测试),检验程序模块(软件设计的最小单位)正确性的测试工作,常常是程序员写的一段代码.对于面向对象编程,最小单元就是方法,包括基类(超类).抽象类.或者派生类(子 ...

  3. Android first --- 单元测试框架junit

    #单元测试junit* 定义一个类继承AndroidTestCase,在类中定义方法,即可测试该方法 * 在指定指令集时,targetPackage指定你要测试的应用的包名 <instrumen ...

  4. Android Studio 单元测试

    在功能测试有时要通过Log来验证,每次编译都需要时间,对于一些功能测试可以用Android Studio自带的单元测试功能进行调试: 在新建项目时,Android studio就已经集成了二个单元测试 ...

  5. Android Studio 单元测试

    测试的种类 按岗位划分 黑盒测试:测试逻辑业务 白盒测试:测试逻辑方法 按测试粒度分 方法测试:function test 单元测试:unit test 集成测试:integration test 系 ...

  6. Android:单元测试

    通过单元测试的方法可以轻松判断BUG 第一步:首先在AndroidManifest.xml中加入下面红色代码: 打开AndroidManifest.xml,选择instrumentation ,选择N ...

  7. Android之单元测试及数据库操作

    一.安卓下的单元测试1.创建一个单元类,继承超类AndroidTestCase2.在AndroidManifest.xml配置清单中配置以下两点首先在manifest节点下添加节点instrument ...

  8. Android+Junit单元测试1

    学习参考: http://my.oschina.net/liux/blog/52469 http://mobile.51cto.com/android-229614.htm 一,权限配置 <ap ...

  9. android的单元测试

    1.新建android Test project 2. 选择针对测试的项目 3.新建类继承AndroidTestCase即可: package com.howlaa.sms.test; import ...

随机推荐

  1. iOS之手势滑动返回功能-b

    iOS中如果不自定义UINavigationBar,通过手势向右滑是可以实现返回的,这时左边的标题文字提示的是上一个ViewController的标题,如果需要把文字改为简约风格,例如弄过箭头返回啥的 ...

  2. webserver<2>

    #include <stdio.h> #include <unistd.h> #include <sys/types.h> #include <sys/wai ...

  3. 移动应用产品开发-android开发(三)

    历时一个多月的时间,这款APP算是开发完成了,最近在测试完善中,比较空闲好好总结下. 之前两次已经提到开发过程中的主要的知识点,这次主要总结下解决问题方法,http请求和安全. 首先讲下解决问题的方法 ...

  4. 【HDU 1133】 Buy the Ticket (卡特兰数)

    Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...

  5. PowerDesigner使用总结 转

    PowerDesigner使用总结 (友情提示:本博文章欢迎转载,但请注明出处:陈新汉,http://www.blogjava.net/hankchen)一.使用PowerDesigner生成HTML ...

  6. Design T-Shirt

    Design T-Shirt Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. Oracle Statspack报告中各项指标含义详解~~学习性能必看!!!

    Oracle Statspack报告中各项指标含义详解~~学习性能必看!!! Data Buffer Hit Ratio#<#90# 数据块在数据缓冲区中的命中率,通常应该在90%以上,否则考虑 ...

  8. WP8模拟器需要BIOS开启虚拟化支持(转载)

    在BIOS里启用hypervisor和virtualization,然后安装WP8 SDK. 如果出现“当前用户未添加到Hyper-V管理组时”, 以管理员身份运行CMD: net localgrou ...

  9. 全新ASP框架——IISNODE介绍

    Asp是一门经典的动态网页编程语言,通常使用vbscript或者Jscript脚本来实现.一个好的框架,可以帮助您更加快速地使用Asp来完成您的网站开发任务.而Asp框架的终结者——IISNODE框架 ...

  10. python进度1

    Python 错误和异常 异常参数: 3.4与2.7有些不同 3.4中 try: x except NameError as e: print(type(e)) print(e) 运行结果: < ...