2015519

23:10

Android中,已经内置了Junit所以不需要在导包。只要继承AndroidTestCase类就可以了。

首先需要修改AndroidManifest.xml

添加配置

<!-- android:name是固定的写法

android:targetPackage表示要调试的包-->

<instrumentation

android:name="android.test.InstrumentationTeatRunner"

android:targetPackage="com.example.junittest"/>

<!-- uses-library的写法是固定的-->

<uses-library android:name="android.test.runner"/>

AndroidManifest.xml的代码如下

<?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" />

<!-- android:name是固定的写法

android:targetPackage表示要调试的包-->

<instrumentation

android:name="android.test.InstrumentationTeatRunner"

android:targetPackage="com.example.junittest"/>

<application

android:allowBackup="true"

android:icon="@drawable/ic_launcher"

android:label="@string/app_name"

android:theme="@style/AppTheme" >

<!-- uses-library的写法是固定的-->

<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>

Junit的测试类

package com.example.junittest;

import junit.framework.Assert;

import android.test.AndroidTestCase;

public class Junittest extends AndroidTestCase {

public void test1()

{

double a=10/2;

Assert.assertEquals(5, a);

}

}

更多相关文章

  1. Kotlin 写 Android 单元测试(四),Robolectric 在 JVM 上测试安卓相
  2. 修改 framework 代码的经验和踩过的坑
  3. android常用颜色代码定义
  4. js与Android和iOS的webview交互,兼容的写法
  5. android 代码proguard
  6. Android日志系统分析之日志设备驱动程序代码阅读
  7. Android Studio实现代码混淆
  8. Android之打开闪光灯关键代码

随机推荐

  1. 【摘录】从Android界面开发谈起
  2. 让Ubuntu和Android同时运行(Ubuntu on And
  3. 《Android》Lesson17-用Fragment实现简易
  4. 每周总结20130821——android控件的尺寸
  5. android tabhost --android UI 学习
  6. Android(安卓)面试之开篇
  7. android中使用OpenCV之调用设备摄像头
  8. Android硬件之传感器
  9. 【Gradle】Android(安卓)Gradle 插件
  10. android中使用OpenCV之调用设备摄像头