采用遗传算法自动生成路径覆盖的测试数据是软件测试自动化研究的热点.现有方法设计适应值函数时,对穿越难以覆盖节点的稀有数据保护不够理想,因而影响测试数据生成效率的提高.文中在测试数据进化生成时动态扑捉稀有数据,通过统计每代种群中目标路径各节点被穿越的个体数量,得到个体对生成穿越目标路径测试数据的贡献,以此作为权重调整个体的适应值,使得稀有数据的适应值增加,以便在后续进化中得到保留,从而提高测试数据生成的效率.基准程序和工业用例的测试结果表明,与传统方法及随机法比较,文中方法生成覆盖路径的测试数据效率较高.
Using genetic algorithms to generate test data for path coverage is a hot topic in soft- ware testing automation. The established fitness functions of previous methods cannot provide adequate protection to a scarce datum which covers a node difficult to be covered, so the efficiency of generating test data needs to be improved. In this study, scarce data are dynamically captured during the evolutionary generation of test data. We obtain the contribution of an individual by counting up the number of individuals which traverse each node of the target path, and regard this contribution as a weight to adjust the fitness of the individual. In this way, the fitness of a scarce datum can be increased and the scarce datum can be kept in the subsequent evolution, so the efficiency of generating test data is improved. The proposed method is applied to generate test data for covering paths of two benchmark and six industrial programs, and is compared with traditional and random methods. The experimental results confirm that the proposed method isefficient in generating test data for path coverage.