什么是蜕变测试(Metamorphic Testing)

发表于:2010-10-19来源:作者:点击数: 标签:TestingtestingOS
下面是一个比较正式的关于蜕变测试(Metamorphic Testing)的定义: Metamorphic testing is used in conjunction with other test case selection strategies Given a test case selection strategy S, such as path coverage, a set of test cases T ={t1,t2

  下面是一个比较正式的关于蜕变测试(Metamorphic Testing)的定义:

  Metamorphic testing is used in conjunction with other test case selection strategies Given a test case selection strategy S, such as path coverage, a set of test cases T ={t1,t2,t3...tn} , where is n>=1 generated. The program is then tested on T . If no failure is revealed after running all in T for i = 2, .. . , n,then T will be a set of suclearcase/" target="_blank" >ccessful test cases.

  At this stage, metamorphic testing can be carried out to generate follow-up test cases according to metamorphic relations. A metamorphic relation (MR) is an expected relation among the inputs and outputs of multiple executions of the target program. For a successful test case and a chosen MR, we can construct follow-up test say ti' and run the program again. Let p denote the program under test. We check ti, p(ti),ti' and p(ti')against the MR. If MR cannot be satisfied, the program must have failed.

  简而言之,蜕变测试是利用一些成功的测试用例来产生后续测试用例的一种技术,我们将后续的测试用例和前者之间的关系称作metamorphic relation(MR)。举一个很简单的例子来说,假设我们有一个计算sin函数的程序(输入值为弧度),一般情况下我们可以利用一些特殊值去进行测试,比如sin(0)=0,sin(Pi/2)=1 等。但是假设我们有这么一个测试用例sin(2)其程序结果为0.909,那我们如何能判定这个结果的正确性呢?这种情况下,我们可以根据一些已知的MR去产生后续测试用例进行测试,比如sin(x)=-sin(-x),sin(x)=sin(pi-x)(这就是MR)等。如果有任何违反以上关系的情况发生,那么我们就可以认定程序中存在错误。

原文转自:http://www.ltesting.net