提出一种新的用于多路径覆盖的测试数据生成方法.首先,将被测程序表示成一棵二叉树,对目标路径采用赫夫曼编码方法表示成二进制串;然后,采用遗传算法生成多个测试数据,设计的适应度函数综合考虑个体穿越的路径与每个目标路径的匹配程度.将提出的方法用于4个基准程序的路径覆盖测试数据生成,并与已有方法比较,结果表明本文方法计算量小,生成测试数据效率高.
An approach to generating test data for multiple paths coverage is presented.First,the program under test is expressed as a binary tree,and the target paths are encoded into a binary string using Huffman coding;then,genetic algorithm is employed to generate multiple test data,and an individual′s fitness is the degree of the traversed path matching the target paths.The proposed approach is applied to 4 benchmark programs,and compared with previous approaches.The results show that the proposed approach needs small amount of calculation and has high efficiency in generating test data.