截图
简介
这是变异测试ppt,包括了变异测试技术,基本思想,程序变异概念,为什么变异,原子反应堆控制软件,应用变异评估测试的充分性等内容,欢迎点击下载。
变异测试ppt是由红软PPT免费下载网推荐的一款课件PPT类型的PowerPoint.
软件测试与质量保证Lecture 5: 白盒测试方法程序变异测试
变异测试技术
变异测试是一种对测试集的充分性进行评估的技术,以创建更有效的的测试集。
变异测试与路径或数据流测试不同,没有测试数据的选择规则。
变异测试应该与传统的测试技术结合,而不是取代它们。
基本思想
给定一个程序P和一个测试数据集T,通过变异算子为P产生一组变异体Mi(合乎语法的变更),对P和M都使用T进行测试运行,如果某Mi在某个测试输入t上与P产生不同的结果,则该Mi被杀死;若某Mi在所有的测试数据集上都与P产生相同的结果,则称其为活的变异体。接下来对活的变异体进行分析,检查其是否等价于P;对不等价于P的变异体M进行进一步的测试,直到充分性度量达到满意的程度。
程序变异概念(1)
假设程序P已使用测试T中的测试用例测试通过,而且没有错误。变异是一种轻微改变程序的操作。
程序变异概念(2)
P’称为P的变异体
如果对于T中的测试t,有P(t)≠P’(t),称作P’与P有区别( distinguishes),或者t杀死(killed)P’.
如果T中所有的测试 t使得P(t)=P’(t),称T不能区别P和P’。那么称在测试过程中P’是活的(live).
如果在程序P的输入域中不存在任何测试用例t使得P与P’ 区别,则称P’等价于P。
如果P’不等价于P,而且T中没有测试能够将P’与P区别,则认为T是不充分的。
不等价而且是活的变异体为测试人员提供了一个生成新测试用例的机会,进而增强测试T。
为什么变异?
A Scenario:
程序员开发了一个程序P,按照某种测试充分性准则通过了测试,即将发布,这时会有人指出:程序中的表达式
count<max 还是
count<max+1
问题:为什么替代的方法不正确,或为什么替代的方法比所选的方法更好?
可能的答案:
性能差别
替代方法“不正确”或更好,而现有方法是“正确的”
通过测试用例表明现有的方法与替代的方法是不同的,而且现有的方法是“正确的”。
表明替代方法与现有方法是等价的
变异是一种解决上述问题的系统的方法,变异测试可以发现程序一些细微的错误——表明替代的方法是不正确的。
例:原子反应堆控制软件P
例:原子反应堆控制软件P’-M1
例:原子反应堆控制软件P’-M2
应用变异评估测试的充分性(1)
Given a test set T for program P that must meet requirements R, a test adequacy assessment procedure proceeds as follows:
Step 1: Create a set M of mutants of P. Let M={M0, M1…Mk}. Note that we have k mutants
Step 2: For each mutant Mi find if there exists a t in T such that Mi(t) ≠P(t). If such a t exists then Mi is considered killed and removed from further consideration.
应用变异评估测试的充分性(2)
Step 3: At the end of Step 2 suppose that k1(≤ k) mutants have been killed and (k-k1) mutants are live
Case 1: (k-k1)=0: T is adequate with respect to mutation.
Case 2: (k-k1)>0 then we compute the mutation score (MS) as follows:
测试充分性评估过程
第1步:程序执行
P(t)表示给定测试用例t,程序P的执行结果由P中变量的输出值表示(也可能与P的性能有关)
如果P已经采用测试T测试通过,测试结果已保存至数据库中,则这一步可以跳过。
不论何种情况,第一步的结果是对于T中的所有t,P(t)数据库
测试充分性评估过程
第2步:生成变异体
例如“+”运算变成“-”运算,“×”运算变成“/”运算等
系统的生成方法:通过变异算子生成
第二步的结果是:活的变异体
这些变异体还没有与程序P区分,即没有被杀死。
测试充分性评估过程
第3步和第4步:选择下一个变异体
从L中选择,任意选择
测试充分性评估过程
第5步和第6步:选择下一个测试用例
是否存在测试t能够区分变异体与被测试程序P
采用测试T中的测试用例执行变异体M。
结束:所有的测试用例执行完毕或者M被某个测试用例区别(杀掉)。
测试充分性评估过程
第7,8和9步:变异体执行和分类
变异体执行的结果是否与P的执行结果相同或不同
第10步:活变异体
如果没有测试用例能够区分变异体与P,则该变异体存活,并被放回活变异体集合L中。
测试充分性评估过程
第11步:等价变异体
如果对于程序P的输入域中的每一个输入,变异体M的执行结果等于P的执行结果,则认为M等价于P。
例
测试充分性评估过程
第12步:变异数的计算
量化评价指标:
=1代表相关于变异T是充分的
<1表示相关于变异T是不充分的
可以通过增加额外的测试用例提高变异数
T的变异数记为MS(T)
其中:|D|表示:杀死的变异体数
|L|表示:表示活的变异体数
|E|表示:等价的变异体数
|M|表示:第2步生成的所有变异体数
测试增强(例)
P使用测试T并测试通过
{t1:<x=0,y=0>,t2:<x=0,y=1>,t3:<x=1,y=0>,t4:<x=-1,y=-2>}
M使用T运行的结果与P相同,无法区分P与M
增加一个测试用例 <x=1,y=1>,使P和M区别,表明增强了T
应用变异查错(1)
Consider the following function foo that is required to return the sum of two integers x and y. Clearly foo is incorrect.
应用变异查错(2)
假设foo已经由测试集合T 测试通过,T包含两个测试用例:
{ t1: <x=1, y=0>, t2: <x=-1, y=0>}
注意:foo在每一个测试用例上返回了期望值 ,而且对于基于控制流和数据流的充分性准则来说T是充分的。
假设foo生成了三个变异体
应用变异查错(3)
应用变异查错(4)
应用变异查错(5)
变异算子(1)
变异算子 O 是一个函数,建立了被测试程序P与P的K(>=0)个变异体间的映射。
变异算子通过对被测试程序做简单的变化生成变异体。
变异算子对编程语言有依赖性,已经开发的、与语言相关的变异算子有 Fortran, C, Ada, Lisp 和 Java等。
变异算子的设计基于经验和一些规则。
变异算子(2)
For example, the “variable replacement” mutant operator replaces a variable name by another variable declared in the program. An “relational operator replacement” mutant operator replaces relational operator with another relational operator
A mutant operator models a simple mistake that could be made by a programmer
Several error studies have revealed that programmers--novice and experts--make simple mistakes. For example, instead of using x<y+1 one might use x<y
While programmers make “complex mistakes” too, mutant operators model simple mistakes. The “coupling effect” explains why only simple mistakes are modeled.
变异算子(例)
一阶和高阶变异体
A mutant obtained by making exactly “one change” is considered first order
A mutant obtained by making two changes is a second order mutant. Similarly higher order mutants can be defined. For example, a second order mutant of z=x+y; is x=z+y; where the variable replacement operator has been applied twice
In practice only first order mutants are generated for two reasons: (a) to lower the cost of testing and (b) most higher order mutants are killed by tests adequate with respect to first order mutants. [See coupling effect later.]
变异测试的理论基础
程序员的能力假设( Competent programmer hypothesis (CPH) ) :被测试程序是由足够程序设计能力的程序员书写的,所产生的程序是接近正确的。
组合效应假设(Coupling Effect) :假设简单的程序设计错误和复杂的程序设计错误之间具有组合效应,即一个测试数据如果能够发现简单的错误,也可以发现复杂的错误。
两个假设来源于软件开发的实验,至今未达到正确性证明,但确定了变异测试的基本特征:通过变异算子对程序做一个较小的语法上的变动来产生一个变异体。
变异测试工具
There are few mutation testing tools available freely.
Proteum for C from Professor Maldonado
muJava for Java from Professor Jeff Offutt.
A typical tool for mutation testing offers the following features
A selectable palette of mutation operators.
Management of test set T
Execution of the program under test against T and saving the output for comparison against that of mutants.
Generation of mutants
变异测试工具的特征(续)
Mutant execution and computation of mutation score using user identified equivalent mutants
Incremental mutation testing: i.e. allows the application of a subset of mutation operators to a portion of the program under test.
Mothra, an advanced mutation tool for Fortran also provided automatic test generation using DeMillo and Offutt’s method
变异与系统测试
Adequacy assessment using mutation is often recommended only for relatively small units.
e.g. a class in Java
a small collection of functions in C
However, given a good tool, one can use mutation to assess adequacy of system tests.
The following procedure is recommended to assess the adequacy of system tests.
测试步骤
测试步骤
变异测试的优缺点
排错能力强
发现错误的能力较强——分析评估的结果
自动化程度高
测试工具自动产生变异体,自动运行P和M,自动发现被杀死的变异体
灵活性高
通过与测试工具的交互,有选择地使用变异算子
变异体与被测试程序的差别信息可以较容易地发现软件的错误。
可以完成语句覆盖和分支覆盖
将每条语句或每个条件用Trap语句代替
需要大量的计算机资源完成充分性分析
N行程序产生O(n2)变异体
存储变异体的开销大
变异体与被测试程序的等价判断需人工判定(判断两个程序是否等价是不可判定的命题)
小结
小结(续)
展开