zoukankan      html  css  js  c++  java
  • Android中的单元测试

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

    }

    }

  • 相关阅读:
    LeetCode-Search a 2D Matrix
    Cocos2d-x 学习(1)—— 通过Cocos Studio创建第一个Demo
    SpringMVC经典系列-12基于SpringMVC的文件上传---【LinusZhu】
    poj 2126 Factoring a Polynomial 数学多项式分解
    [每天读书半小时] 2015-6-8 设计模式
    LeetCode_Path Sum II
    MySql截取DateTime字段的日期值
    Fiddler2 中文手册
    fiddler2抓包工具使用图文教程
    Fiddler2 抓取手机APP数据包
  • 原文地址:https://www.cnblogs.com/yxx123/p/4519912.html
Copyright © 2011-2022 走看看