Related concepts of testing

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

黑盒:功能测试。

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

根据测试的粒度。

方法测试:

单元测试:

集成测试:

系统测试:

根据测试的暴力程度。

压力测试:谷歌工程师给我们提供了一个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搞丢了,找不到需要配置的东西,可以创建针对当前需要测试的工程,搞一个测试工程,测试工程的清单文件里面会将这两项配置自动更新出来。

posted @ 2018-09-16 14:01  小步快跑!!!!!  阅读(257)  评论(0编辑  收藏  举报