当前位置: 移动技术网 > IT编程>移动开发>Android > Related concepts of testing

Related concepts of testing

2018年09月16日  | 移动技术网IT编程  | 我要评论

11月份有什么节日,美人猎色,宋紫菲

根据是否知道源代码测试可以分为黑盒和白盒。

黑盒:功能测试。

白盒:知道源代码,要写测试代码。

根据测试的粒度。

方法测试:

单元测试:

集成测试:

系统测试:

根据测试的暴力程度。

压力测试:谷歌工程师给我们提供了一个monkey + 次数指令可以进行压力测试。

冒烟测试:

在android工程下创建了一个这样的类,运行的时候有异常。

 1 package com.example.unit;
 2 
 3 public class test {
 4 
 5     /**
 6      * @param args
 7      */
 8     public static void main(string[] args) {
 9         // todo auto-generated method stub
10         system.out.println("哈哈");
11     }
12 
13 }

invalid layout of java.lang.string at value
#
# a fatal error has been detected by the java runtime environment:
#
# internal error (javaclasses.cpp:136), pid=4608, tid=3764
# fatal error: invalid layout of preloaded class
#
# jre version: (7.0_72-b14) (build )
# java vm: java hotspot(tm) client vm (24.72-b04 mixed mode windows-x86 )
# failed to write core dump. minidumps are not enabled by default on client versions of windows
#
# an error report file with more information is saved as:
# d:\android\adt-bundle-windows-x86-20131019\workspace\单元测试\hs_err_pid4608.log
#
# if you would like to submit a bug report, please visit:
# http://bugreport.sun.com/bugreport/crash.jsp
#

分析:android工程是运行在dalivk虚拟机上的,是运行在手机里面的,手机里面谷歌封装了一个dalivk虚拟机,这段代码是java代码是运行在jvm上的,所以会挂掉。

要进行单元测试,android中需要继承 androidtestcase这个类。

 1 package com.example.unit;
 2 
 3 import android.test.androidtestcase;
 4 
 5 public class calctest extends androidtestcase {
 6     public void testadd() {
 7         calc calc = new calc();
 8         int result = calc.add(3, 5);
 9         assertequals(8, result);
10     }
11 }

如果直接运行上面的代码会报异常,does not specify a android.test.instrumentationtestrunner instrumentation or does not declare uses-library android.test.runner in its androidmanifest.xml(没有指定android.test。在其androidmanifest.xml文件中,未声明use -library android.test.runner)需要在清单文件里面配置函数库。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <manifest xmlns:android="http://schemas.android.com/apk/res/android"
 3     package="com.example.unit"
 4     android:versioncode="1"
 5     android:versionname="1.0" >
 6 
 7     <uses-sdk
 8         android:minsdkversion="8"
 9         android:targetsdkversion="17" />
10     <instrumentation android:name="android.test.instrumentationtestrunner"
11                 android:targetpackage="cn.example.unit" android:label="tests for my app" />
12 
13     <application
14         android:allowbackup="true"
15         android:icon="@drawable/ic_launcher"
16         android:label="@string/app_name"
17         android:theme="@style/apptheme" >
18         <uses-library android:name="android.test.runner" />
19         <activity
20             android:name="com.example.unit.mainactivity"
21             android:label="@string/app_name" >
22             <intent-filter>
23                 <action android:name="android.intent.action.main" />
24 
25                 <category android:name="android.intent.category.launcher" />
26             </intent-filter>
27         </activity>
28         
29     </application>
30 
31 </manifest>

 1 <uses-library android:name="android.test.runner" /> 这段代码的作用是告诉系统我要用到系统的一些函数库。

1 <instrumentation android:name="android.test.instrumentationtestrunner"
2                 android:targetpackage="cn.example.unit" android:label="tests for my app" />

这行代码的作用是:指定我要测试哪个应用。

如果说ppt搞丢了,找不到需要配置的东西,可以创建针对当前需要测试的工程,搞一个测试工程,测试工程的清单文件里面会将这两项配置自动更新出来。

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网