一句话:ExLi 首次实现从单元测试自动提取内联测试,并用覆盖率与变异体约简去除冗余。
内联测试允许开发者在目标语句后直接给出测试输入、期望输出和测试预言,但已有代码中目标语句数量庞大,自动生成内联测试成为推广该技术的关键。本文提出 ExLi,这是首个自动生成内联测试的技术。ExLi 在运行单元测试时记录目标语句处的所有变量值,将其作为初始内联测试的输入和预言;针对同一语句被多次执行产生的冗余测试,ExLi 采用新颖的“先覆盖率、后变异体”约简流程筛选测试。作者为 Java 实现 ExLi,并在 31 个开源程序的 718 个目标语句上评估。ExLi 将 17,273 个初始内联测试缩减为 905 个,最终生成的内联测试在目标语句上比开发者编写及自动生成的单元测试最多多杀死 25.1% 的变异体,表明其能提升原测试套件的故障检测能力。
We recently proposed inline tests for validating individual program statements; they allow developers to provide test inputs, expected outputs, and test oracles immediately after a target statement. But, existing code can have many target statements. So, automatic generation of inline tests is an important next step towards increasing their adoption. We propose ExLi, the first technique for automatically generating inline tests. ExLi extracts inline tests from unit tests; it first records all variable values at a target statement while executing unit tests. Then, ExLi uses those values as test inputs and test oracles in an initial set of generated inline tests. Target statements that are executed many times could have redundant initial inline tests. So, ExLi uses a novel coverage-then-mutants based reduction process to remove redundant inline tests. We implement ExLi for Java and use it to generate inline tests for 718 target statements in 31 open-source programs. ExLi reduces 17,273 initially generated inline tests to 905 inline tests. The final set of generated inline tests kills up to 25.1% more mutants on target statements than developer written and automatically generated unit tests. That is, ExLi generates inline tests that can improve the fault-detection capability of the test suites from which they are extracted.