Mutation Testing/Analysis 突变测试

突变测试 定义

突变(mutation),即基因突变。在遗传学(genetics)上,指的是器官、病毒或者染色体外的其他遗传成分基因的核酸(nucleotide)序列发生改变。基因突变多发生在DNA复制期间。可能的诱发因素是辐射,外伤,病毒,或者空气污染、危险食物带来的有害化学物质的影响,也可能是无从索迹的任何其它原因。

突变测试(mutation testing) , 或称作突变分析、程序突变,它是用于衡量软件测试的质量。突变测试通常对程序的源代码或者目标代码做小的改动,并把截然不同的错误行为(或者怪异行为)作为预期。如果测试代码没有觉察到这种小改动带来的错误,就说明这个测试是有问题的。

举例:正常程序:

...
if (a < 0) {
 Assert.fail();
} else {
 System.out.println (" I am fine "); 
}
...

为了测试到程序失败的情况,可以给程序加入突变代码:
突变程序:

...
a = -1; //突变代码,这个代码足够让程序产生一些怪异行为。。。
if (a < 0) {
 Assert.fail();
} else {
 System.out.println (); 
}
...

当然,如果程序测试时没有爆出如期所愿的怪异行为(或者失败),就说明测试程序是有问题。

IEEE (Std 610.12-1990) 对突变测试定义如下:

Mutation testing. A testing methodology in which two or more program mutations are executed using the same test cases to evaluate the ability of the test cases to detect differences in the mutations.

即:突变测试 (mutation testing) 一种测试方法。指对两个或两个以上程序的变异(mutation),采用相同的测试用例进行测试。目的是评估测试用例发现变种间不同的能力。

突变测试是用于测试测试用例的。类似于背对背测试但又有明显的不同。
IEEE (Std 610.12-1990) 对背对背测试定义如下:
背对背测试 (back-to-back testing) 一种测试方法。指对两个或两个以上程序的变体(variant) 对比测试。采用相同的测试用例和相同的输入,对产生的结果进行比较。比较的重点是错误差异(discrepancies)分析。

从字面上理解,变体还都是正常的范畴,变异则是怪物的同义词。

以上转自:http://blog.sina.com.cn/s/blog_66e177dd0101au88.html


…If the test suite is able to detect the change (i.e. one of tests fails), then mutant is said to be killed.

For example, let’s consider the following C++ code fragment:

if (a && b)
    c = 1;
else
    c = 0;

The condition mutation operator would replace ‘&&’ with ‘||’ and produce the following mutant:

if (a || b)
    c = 1;
else
    c = 0;

Now, for the test to kill this mutant, the following condition should be met:

Test input data should cause different program states for mutant and original program. For example, a test with a=1 and b=0 would do this.
The value of ‘c’ should be propagated to the program’s output and checked by the test.

Weak mutation testing (or weak mutation coverage) requires that only the first condition is satisfied.
Strong mutation testing requires that both conditions are satisfied.
Strong mutation is more powerful, since it ensures that the test suite can really catch the problems. Weak mutation is closely related to code coverage methods. It requires much less computing power to ensure that the test suite satisfies weak mutation testing than strong mutation testing.
————————————————
版权声明:本文为CSDN博主「icyxiaoxiang」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/icyxiaoxiang/article/details/4472918

Mutation Analysis 过程

Mutation testing typically involves three stages:

  1. Mutant generation : a predefined set of mutation operators are used to generate mutants from program source code or bytecode. A mutation operator is a rule that is applied to a program to create mutants, such as arithmetic operator replacement(AOR).预定义的一组突变运算符用于从程序源代码或字节码生成突变。 变异算子是应用于程序以创建变异的规则,例如算术算子替换(AOR)。
  2. Mutant execution :the goal is execution of test cases against both the original program and the mutants.目标是针对原始程序和变体执行测试用例。
  3. Result analysis : the goal is to check the mutation score obtained by the test suite, where mutation score is defined as the ratio of the number of killed mutants to the number of all(non-equivalent) generated mutants. 目的是检查测试套件获得的突变评分,其中突变评分定义为被杀死的突变体数量与所有(非等价)生成的突变体数量之比。

存在单一错误的突变体称为first-order mutants。
对于并发软件来说,由于复杂的线程同步措施,first-order mutants 对细微的调整并不有效。需要higher-order mutants inserting two or more faults.

发布了27 篇原创文章 · 获赞 1 · 访问量 683

猜你喜欢

转载自blog.csdn.net/SUKI547/article/details/102716506
今日推荐