软件测试-chapte4-Graph Coverage
Posted 陈煜弘
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了软件测试-chapte4-Graph Coverage相关的知识,希望对你有一定的参考价值。
1.Outline
•Introduction to Graph Coverage
• Graph Coverage Criteria
• Control Flow Graph Coverage
• Data Flow Graph Coverage
2.图在软件测试中应用广泛,并且图的来源有:
– Control flow graphs (控制流图)
– Design structure(设计结构)
– FSMs and statecharts(有限状态自动机(FSM "finite state machine" )和 状态转换图)
– Use cases (测试用例)
测试意图通过某种方式覆盖整个图的所有方面
3.图的定义
• A set N of nodes, N is not empty
• A set N0 of initial nodes, N0 is not empty(注意起始节点不能为空,意思是图中必定出现只有后继没有前驱的节点)
如 而不是
• A set Nf of final nodes, Nf is not empty (终结点不为空)
• A set E of edges, each edge from one node to another – ( ni , nj ), i is predecessor, j is successor(i为前驱,j为后继)
4. 图的path
path:A sequence of nodes – [n1, n2, …, nM]
并且每一对节点都是一条边
Length : The number of edges – A single node is a path of length 0 (单节点也是有长度的为0)
Subpath : A subsequence of nodes in p is a subpath of p
Reach (n) : Subgraph that can be reached from n (从n可以到达的子图)
5. Test Paths and SESEs (测试路径和单入单出路径)
Test Path : A path that starts at an initial node and ends at a final node (包含初始结点和终结点)
Test paths represent execution of test cases 测试路径意味着测试用例的执行,但是一些测试用例可能不能覆盖到所有的测试路径
– Some test paths can be executed by many tests
– Some test paths cannot be executed by any tests
SESE graphs : All test paths start at a single node and end at another node (初始和终结点不同,因此至少两个节点)
6. Visiting and Touring
Visit : A test path p visits node n if n is in p (测试路径中的单个节点或边)
Tour : A test path p tours subpath q if q is a subpath of p(测试路径中的子路径)
7. Tests and Test Paths
• path (t) : The test path executed by test t
• path (T) : The set of test paths executed by the set
并且每一个测试(这里相当于一次具体的测试用例)只能去测试一条测试路径
– Syntactic reach : A subpath exists in the graph (语法到达,从测试路径图上看可以到达)
– Semantic reach : A test exists that can execute that subpath(语义到达,设计的一组测试用例能够执行该条测试路径)
GRAPH COVERAGE CRITERIA (图的覆盖标准)
1.Testing and Covering Graphs (2.2)
• Test Requirements (TR) : Describe properties of test paths (描述了测试路径需要满足的条件)
• Test Criterion : Rules that define test requirements ()
• Satisfaction : Given a set TR of test requirements for a criterion C, a set of tests T satisfies C on a graph if and only if for every test requirement in TR, there is a test path in path(T) that meets the test requirement tr
• Structural Coverage Criteria : Defined on a graph just in terms of nodes and edges
• Data Flow Coverage Criteria : Requires a graph to be annotated with references to variables
几种结构覆盖:
Node Coverage (NC) :节点覆盖的TR中必须包含图G中每个可达的节点
Edge Coverage (EC) : TR contains each reachable path of length up to 1, inclusive, in G.(注意:边覆盖TR必须包括每条可达的测试路径而且它的长度至少最多是1,这句话并不是说边覆盖就包含了节点覆盖,它们是不同的,因为当图只包含一个节点时,为了边覆盖的定义不得不作出节点长度为0这样折中的方案,意思是让所有的图都能具有这几种结构覆盖的定义,包括只有一个节点的图,类似的还有边对覆盖对于只有两个节点的图的情况)
Edge-Pair Coverage (EPC) : TR contains each reachable path of length up to 2, inclusive, in G. (边对覆盖包含至少两条长度为2的测试路径)
Complete Path Coverage (CPC) : TR contains all paths in G. (完全路径覆盖,当然如果路径中有循环则所有情况是不可能完全列举出来,因此CPC并不合理)
Specified Path Coverage (SPC):指定路径覆盖,即指定测试路径集合S,但是测试路径并不令人满意,因为会随着测试者的变动结果会变得不一样
示例:
现在可以使用主路径处理循环问题
Simple Paths and Prime Paths (简单路径和主路径)
Simple Path : A path from node ni to nj is simple if no node appears more than once, except possibly the first and last nodes are the same (除了初始节点和终结点外,该路径中没有任何一个节点出现两次,那么就是一条简单路径)
Prime Path : A simple path that does not appear as a proper subpath of any other simple path 主路径:一条从ni到nj的路径,如果是一个简单路径且不会作为任何其他简单路径的固有子路径出现(意思是这一条简单路径不能成为比它长的简单路径的子路径,也就是不能被其他简单路径所包含),我们称这条路径为主路径。
Prime Path Coverage:TR contains each prime path in G.(主路径覆盖,将会遍历所有长度为0,1及以上的,意味着包括了点覆盖和边覆盖,但是边对覆盖不是主路径覆盖的子集)
如; • If a node n has an edge to itself,EPC will require [n, n, m]
• [n, n, m] is not prime
主路径不包括内部循环,而测试路径却可能包括
• Tour With Sidetrips(有侧访的游历) : A test path p tours subpath q with sidetrips if every edge in q is also in p in the same order • The tour can include a sidetrip, as long as it comes back to the same node
• Tour With Detours (有绕路的游历): A test path p tours subpath q with detours if every node in q is also in p in the same order • The tour can include a detour from node ni, as long as it comes back to the prime path at a successor of ni
推荐:Best Effort Touring :1.在不使用侧访的情况下尽最大可能满足TR 2.使用侧访时尽力满足不怎么让人满意的测试需求
2. Data Flow Criteria
目标:保证变量值被正确地使用和计算
Definition (def) : A location where a value for a variable is stored into memory (定义变量的位置)
Use : A location where a variable’s value is accessed 存取变量值的位置
DU pair: A pair of locations (li, lj) such that a variable v is defined at li and used at lj(定义使用对)
Def-clear: A path from li to lj is def-clear with respect to variable v if v is not given another value on any of the nodes or edges in the path (定义清楚的,路径中变量值被定义后变量值没有再被更改)
Reach : If there is a def-clear path from li to lj with respect to v, the def of v at li reaches the use at lj
du-path : A simple subpath that is def-clear with respect to v from a def of v to a use of v
du (ni, nj, v) – the set of du-paths from ni to nj
du (ni, v) – the set of du-paths that start at ni
Data Flow Test Criteria(数据流测试标准)
All-defs coverage (ADC) : For each set of du-paths S = du (n, v), TR contains at least one path d in S. 每个定义对应一次使用
All-uses coverage (AUC) : For each set of du-paths to uses S = du (ni, nj, v), TR contains at least one path d in S. 每个定义到达该定义可能的使用(一次就行)
All-du-paths coverage (ADUPC) : For each set S = du (ni, nj, v), TR contains every path d in S. 所有定义到达所有可能的使用
图的包含关系:
3.CONTROL FLOW GRAPH COVERAGE(控制流图覆盖)
一个控制流图是通过描述控制结构对一个方法(函数)的所有执行过程的建模,由以下几个部分组成:
Nodes : Statements or sequences of statements (basic blocks) 语句或语句块
Edges : Transfers of control 传递控制
Basic Block : A sequence of statements such that if the first statement is executed, all statements will be (no branches)
4. DATAFLOW GRAPH COVERAGE(数据流图覆盖)
以上是关于软件测试-chapte4-Graph Coverage的主要内容,如果未能解决你的问题,请参考以下文章