一句话:提出基于对象构造图的测试种子合成,使经典适应度度量可用于对象输入,并提升基于搜索的单元测试生成。
基于搜索的软件测试(SBST)通过适应度度量引导测试生成,但当被测函数接收对象输入时,经典度量难以指导构造合法对象,导致适应度地形不连续。本文提出测试种子,即合法对象的测试代码骨架。针对目标分支,静态分析函数并构建对象构造图,刻画目标方法操作数与其相关对象输入状态之间的关系;再据此合成带可变槽位的测试模板,槽位作为搜索算法的变异点。该方法可无缝集成现有 SBST 算法,并在 EvoSuite 上实现 EvoObj。在 103 个开源 Java 项目、2750 个方法上,EvoObj 使用先进 SBST 算法显著优于 EvoSuite。
Search-based software testing (SBST) generates tests using search algorithms guided by measurements gauging how far a test case is away from exercising a coverage goal. The effectiveness of SBST largely depends on the continuity and monotonicity of the fitness landscape decided by these measurements and the search operators. Unfortunately, the fitness landscape is challenging when the function under test takes object inputs, as classical measurement hardly provide guidance for constructing legitimate object inputs. To overcome this problem, we propose test seeds, i.e., test code skeletons of legitimate objects which enable the use of classical measurements. Given a target branch in a function under test, we first statically analyze the function to build an object construction graph that captures the relation between the operands of the target method and the states of their relevant object inputs. Based on the graph, we synthesize test template code where each "slot" is a mutation point for the search algorithm. This approach can be seamlessly integrated with existing SBST algorithms, and we implemented EvoObj on top of EvoSuite. Our experiments show that EvoObj outperforms EvoSuite with statistical significance on 2750 methods over 103 open source Java projects using state-of-the-art SBST algorithms.