1 / 41

软件测试

软件测试. 顾庆 南大计算机系 2001年4月7日. 一、测试的概念. 定义:验证被测程序确实是按照事先预定的目标和规则执行的一个信心建立过程- Hetzal。 两个要求: 程序的正确性 测试过程的可信程度. 一、测试的概念. 什么是程序的正确性 狭义:程序运行符合规约的要求: 功能 性能 输入和输出 对环境的影响 同标准、约定( convention) 的一致性等. 一、测试的概念. 什么是程序的正确性 广义:测试工程,覆盖需求、概要设计、详细设计、编码等软件开发各个阶段 各阶段文档的一致性 向前/向后兼容性 同其他应用程序的协作、接口等.

jenna
Download Presentation

软件测试

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 软件测试 顾庆 南大计算机系 2001年4月7日

  2. 一、测试的概念 • 定义:验证被测程序确实是按照事先预定的目标和规则执行的一个信心建立过程-Hetzal。 • 两个要求: • 程序的正确性 • 测试过程的可信程度

  3. 一、测试的概念 • 什么是程序的正确性 • 狭义:程序运行符合规约的要求: • 功能 • 性能 • 输入和输出 • 对环境的影响 • 同标准、约定(convention)的一致性等

  4. 一、测试的概念 • 什么是程序的正确性 • 广义:测试工程,覆盖需求、概要设计、详细设计、编码等软件开发各个阶段 • 各阶段文档的一致性 • 向前/向后兼容性 • 同其他应用程序的协作、接口等

  5. 一、测试的概念 • 什么是验证过程的可信度 • 选择测试用例的充分性准则 • 结点覆盖准则/边覆盖准则 • 可靠性-多个测试用例集得到一致的结果 • 正确性-程序不正确,至少有一个测试用例能检测出来

  6. 2 P S S-规约视角 P-结构视角 T-测试视角 5 6 1 4 3 7 T 二、测试的基本原理 • 测试对象:程序的行为(程序的执行过程) • 程序行为的三个不同视角(View): • 规约:程序应该做什么 • 结构:程序能够做什么 • 测试:程序做了什么 • Venn_图:

  7. 二、测试的基本原理 • 测试的两个基本类型: • 目的:选择测试用例 • 规约视角+测试视角:功能测试&黑箱测试 • 结构视角+测试视角:结构测试&白箱测试 • 测试的经验定律: • %20的代码导致%80的错误

  8. 二、测试的基本原理 • 描述程序规约的五个基本要素 • 数据:由程序或程序模块创建并使用的信息。 • 端口:程序/模块同外部环境的接口,包括输入和输出。 • 动作:程序状态的变迁,一般对应于程序流图的节点或边。 • 事件:程序/模块同外部环境的交互,可以理解为通过端口的程序动作。 • 线索:动作序列,一般起始于一个输入动作,并终止于一个输出动作。

  9. 数据 动作 线索 端口 程序/模块 事件 二、测试的基本原理 • 五个基本要素间的关系:传统串行程序

  10. 数据2 数据1 动作2 动作1 端口2 端口1 分布单元2 分布单元1 线索 事件2 事件1 二、测试的基本原理 • 五个基本要素间的关系:分布式程序

  11. 二、测试的基本原理 • 测试用例的基本形式: • 单纯的程序输入,适于单个模块的测试。 • 程序的功能脚本-profile,适于多个模块合作的测试 • 程序的线索-thread,适于GUI等的测试。动作序列事件序列:分布式程序测试

  12. a Predicate node F T b x F T y x 三、测试方法和技术 • 白箱测试: • 程序流图(Flow Graph Notation) • 结点-程序语句+条件选择语句 • if (a or b) then x else y :

  13. 三、测试方法和技术 • 白箱测试 • Cyclomatic Complexity = number of independent path,记为V(G) • V(G) = E – N +2 = P + 1 • E – number of edges • N – number of nodes • P – number of predicate nodes

  14. 三、测试方法和技术 • 白箱测试 • 控制流测试: • 结点覆盖 • 分支覆盖-选择独立路径 • 路径覆盖-考虑循环 • 基本路径覆盖(结点不重复出现) • 简单路径覆盖(边不重复出现) • K度回路覆盖(循环重复不超过K次)

  15. 三、测试方法和技术 • 白箱测试 • 数据流测试: • 两类结点: • 变量定义结点-定义性出现 • 变量使用结点-引用性出现:谓词引用/计算引用 • 定义-使用路径(definition-use chain) • 覆盖准则: • 定义覆盖:定义到某一相关引用 • 引用覆盖:定义到所有引用 • 定义-引用覆盖:定义×引用 • 程序片:其他对引用有影响的结点

  16. 三、测试方法和技术 • 白箱测试 • 数据流测试 • 其他覆盖准则: • K元数据交互链: • def(v1) … def(v2) use v1…def(v3) use v2……use vk • 构造类型数据、动态数据(对象绑定)覆盖-各属性的定义和引用 • 过程间数据流(参数传递)

  17. 三、测试方法和技术 • 白箱测试 • 循环的测试 • 单个循环(simple loop):执行次数-0、1、2、n-1、n、n+1 • 嵌套循环(nested loop):由内向外 • Concatenated loops:dependent loops

  18. 三、测试方法和技术 • 黑箱测试 • 边界值分析 • 输入边界:x: min(x), max(x);y: min(y), max(y) • <min(x), norm(y)>, <norm(x), min(y)>, <min(x), min(y)> • <max(x), norm(y)>, <norm(x), max(y)>, <max(x), max(y)> • <min(x), min(y)>, <max(x), max(y)>, <norm(x), norm(y)> • 考虑min+1, max-1, min-1, max+1 • 输出边界:定义f-1

  19. 三、测试方法和技术 • 黑箱测试 • 等价类划分:for every input x- • Specific value: 1 valid + 2 invalid class • Set: 1 valid + 1 invalid class • Range: 1 valid + 2 invalid class • Boolean: 1 valid + 1 invalid • 决策表-classes 1 × classes 2 ×……

  20. 三、测试方法和技术 • 黑箱测试 • Graph-based Testing Methods • Nodes + edges • Transaction Flow-结点:steps in transaction;边-logical connection between steps • Finite state-结点:observable states;边:transition between states • Data flow-结点:data objects;边:transformation between data objects • Timing-结点:program objects;边:sequential connections

  21. 三、测试方法和技术 • 黑箱测试 • Graph-based Testing Methods • 覆盖准则: • 结点覆盖 • 边覆盖 • 路径覆盖(输入路径覆盖、输出路径覆盖)

  22. 四、面向对象测试技术 • 对象技术的影响: • Class – objects • Snapshot of states of an object • Inheritance • Polymorphism – exactly which code gets exercised can only be determined at runtime • Surface structure or deep structure • Surface structure: externally observable structure of an OO program—object interactions • Deep structure: internal details of a class and an object—inheritance hierarchy, attributes, private data, operations

  23. 四、面向对象测试技术 • 单个类的测试方法 • Random Testing: • Operation(method) sequence of the class • Partition Testing: • State-based partitioning • Attribute-based partitioning – attributed used or affected • Category-based partitioning – generic function performed, such as 初始化、查询、终止、计算等

  24. 四、面向对象测试技术 • 涉及多个类的测试方法 • Multiple classes: • 1 class operationsmessagescollaborator class • Random or Partition Testing based • Behavioral model: • State-transition diagram (STD) • One STD – state or transition based coverage • Multiple STD – track the behavioral flow of the system: 深度优先或广度优先

  25. 四、面向对象测试技术 • 涉及多个类的测试方法 • Scenario-based: • Use pattern – what the user does? • From design – which interaction subjects to failure

  26. 五、Client/Server系统的测试 • 测试考虑:3个层次 • Client applications • Client + server • Client + server + network operations & performance • User scenarios: address • Who: type of user • Where: system interaction • What: transactions • Why: domain specific • Operational profiles: pattern of usage

  27. 五、Client/Server系统的测试 • 测试方法(不同的侧重): • Application function • Server test – include performance & coordination & data management • Database test – integrity of data, inquiry accuracy • Transaction test – class of transactions, including performance & interactions • Network communication test – performance, security, correctness etc.

  28. 五、Client/Server系统的测试 • 其他方面 • Configuration testing: in all of known hardware/software environments • Compatibility testing: functionally consistent interface across hardware & software platforms

  29. 六、分布式程序测试 • 分布式程序测试所面临的问题:两个方面 • 分布式程序本身的问题-分布单元间的并发所导致的不确定性。 • 同运行环境合作的问题-分布单元间的协作(通信+同步)需要底层系统的支撑。

  30. 六、分布式程序测试 • 分布式程序自身的问题-并发 • Irreproducibility effect -执行过程不可重复 • 程序p执行输入x,1~n次正确不代表p执行x正确。 • 执行出错时,debug时难以再重复该执行过程。 • 回归测试时不能保证查错的正确性。 • 解决方案: • Record&Replay-记录程序的执行过程。目前多采用事件序列。并根据事件序列以确定的方式执行(重现)被测程序。

  31. 六、分布式程序测试 • Completeness problem-并发路径的覆盖 • Sequentialize并发路径将导致指数级的路径数。 • 竞争条件(race conditions)决定并发路径的选择。 • 解决方案: • 找出并控制竞争条件,实现确定性测试。 • 合理的测试充分性准则-确定有限的路径集(引申为事件序列集)是否是充分的。如“use profile”

  32. 六、分布式程序测试 • 分布式程序同运行环境协作的问题 • 网络的协议架构(TCP/IP+上层应用),分布式程序=建立在通信平台上的分布式应用。 • 建立在通信平台上的分布式程序支撑系统-协议框架+服务构件:如JVM(Java Virtual Machine)、CORBA(Common Object Request Broker)、DCOM(Distributed Common Object Model)-实现互操作、平台无关性等。 • 运行环境=通信平台+支撑系统

  33. 六、分布式程序测试 • 测试时需考虑: • 运行环境(支撑系统)的正确性 • 程序单元同运行环境合作的正确性 • 同运行环境合作的性能 • 解决方法: • 测试功能的分层+测试工具间的合作分布式程序的测试模型 • 分层指测试不同层次的构件和模块。 • 合作指针对不同构件的测试工具(构件来自不同的产商)间的协作。

  34. 六、分布式程序测试 • 分布式程序的测试方法:目前多考虑程序本身。如果考虑运行环境,可参照Client/Server系统的测试。 • 从测试过程和手段划分: • 不确定性测试-给定输入x让程序p自由运行,再观察对应的输出结果,目的是尽可能多地了解程序运行的可行结果,即Feasible(p, x)。 • 确定性测试-给定输入x,根据Valid(p, x)或inValid(p, x)人为干预程序的执行,使其向预想的状态转移或者执行预定的动作,以检测可能的错误; 目的是检测规约行为即Valid(p, x)的可行性。

  35. 六、分布式程序测试 • 两者的结合: • 先按照不确定性测试方法执行分布式程序p,到达一定覆盖程度后再使用确定性测试。 • 在单元和集成测试阶段程序规模较小时采用确定性测试,到系统测试阶段采用不确定性测试。 • Prefix-based Testing(Prefix-based Replay),纵向划分。首先确定同步序列的前缀s’,利用确定性测试到达被测程序的某一中间状态st’,再执行不确定性测试到程序结束。 • Event-subset Testing,横向划分。将程序p按分布单元或共享数据(一般由Server单元管理)分成两个部分,其中之一执行确定性测试,另外一个则执行不确定性测试。 如p分两个模块a和b,测试时按“a.e1, a.e2, …, a.en”,中间穿插b的事件。

  36. 六、分布式程序测试 • 按测试用例的选择方法划分: • 基于有限状态机(如可达图或并发图)的覆盖策略:T方案-每个变迁至少遍历一次;D方案-针对每个中间状态st,选择输入使其执行一个不同的到达终止状态的变迁序列;U方案-针对每个中间状态st,确定输入使其执行一“独特”的变迁序列;W方案-进一步考虑错误状态,基于U方案选择输入/输出序列。 • 基于抽象程序表示(abstract programs):首先采用时序逻辑或进程代数等表示分布式程序,如LOTOS,Estelle,FSP等,再根据这些抽象程序表示选择测试用例。 • 基于同步序列约束(sequencing constraints):当给定程序p和输入x时,穷举Valid(p, x)一般在计算上不可行。一种解决办法是定义同步序列约束如CSPE(Constraints on Succeeding and Preceding Events),它规定前后两个同步动作间的顺序依赖关系以及这种关系的或然性。可以根据对这些约束的覆盖要求选择测试用例。

  37. 七、测试过程 • Policy – 原则 • Design&coding – constructive, while testing – destructive == need ITG (Independent test group) • Verification & Validation • Verification – correctly implements a specific function. • Validation – traceable to customer requirements

  38. 七、测试过程 • Testing Strategy • Coding = unit testing • Design = integration testing • Requirements = validation testing • System = system testing • When suffice? • Software reliability model: 一些经验模型

  39. 七、测试过程 • 单元测试(Unit Testing) • 考虑因素: • Interface • Local data structure • Boundary conditions • Independent paths • Error handling paths • 要素: • Driver – code calling this unit • Stub – dummy function called by this unit

  40. 七、测试过程 • 集成测试(Integration Testing) • Interfacing & Interactions • Incremental integration • 集成方法: • Top-down – stubs • Bottom-up – drivers • Regression testing – subset of previous tests, play back • Sandwich testing – top down while bottom up

  41. 七、测试过程 • 验证测试(Validation Testing) • Configuration review (audit) • Alpha & Beta testing • Alpha: at developer’s site, used by customer • Beta: at the selected customer sites • 系统测试(System Testing) Cooperate with other system elements • Recovery testing = fault tolerance • Security testing • Stress testing

More Related