arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2408.15815cs.SE
收藏

MR-Adopt:用于元形态测试的输入转换函数自动推导

MR-Adopt: Automatic Deduction of Input Transformation Function for Metamorphic Testing

The Hong Kong University of Science and Technology(香港科技大学);Guangzhou HKUST Fok Ying Tung Research Institute(广州香港科技大学霍英东研究院);The University of Auckland(奥克兰大学)

Congying Xu, Songqiang Chen, Jiarong Wu, Shing-Chi Cheung, Valerio Terragni, Hengcheng Zhu, Jialun Cao

AI总结:

MR-Adopt通过自动推导输入转换函数,使元形态关系能够重用新输入提升测试充分性,实验显示其在测试覆盖率和变异评分上有显著提升。

摘要:

尽管最近研究表明许多开发者编写的测试用例可以编码可重用的元形态关系(MR),但超过70%的用例直接硬编码源输入和后续输入在编码关系中。这些不包含显式输入转换以将源输入转换为相应后续输入的编码MR无法与新源输入重用以提高测试充分性。在本文中,我们提出MR-Adopt(自动推导输入转换)以自动推导输入转换,旨在使编码的MR能够与新源输入重用。通常仅有一个源输入和后续输入对可用在MR编码测试用例中作为示例,我们利用大语言模型(LLMs)来理解测试用例的意图并生成额外的源-后续输入对示例。这有助于引导生成可推广到多个源输入的输入转换。此外,为了缓解LLMs生成错误代码的问题,我们通过数据流分析去除与MR无关的代码元素来优化LLM生成的转换。最后,我们基于编码的输出关系评估候选转换并选择最佳转换作为结果。评估结果表明,MR-Adopt可以为72.00%的编码MR生成适用于所有实验源输入的输入转换,比使用普通GPT-3.5高出33.33%。通过将MR-Adopt生成的输入转换纳入MR-基于的测试用例,可以有效提高测试充分性,分别增加行覆盖率和变异评分10.62%和18.91%。

英文摘要:

While a recent study reveals that many developer-written test cases can encode a reusable Metamorphic Relation (MR), over 70% of them directly hard-code the source input and follow-up input in the encoded relation. Such encoded MRs, which do not contain an explicit input transformation to transform the source inputs to corresponding follow-up inputs, cannot be reused with new source inputs to enhance test adequacy. In this paper, we propose MR-Adopt (Automatic Deduction Of inPut Transformation) to automatically deduce the input transformation from the hard-coded source and follow-up inputs, aiming to enable the encoded MRs to be reused with new source inputs. With typically only one pair of source and follow-up inputs available in an MR-encoded test case as the example, we leveraged LLMs to understand the intention of the test case and generate additional examples of source-followup input pairs. This helps to guide the generation of input transformations generalizable to multiple source inputs. Besides, to mitigate the issue that LLMs generate erroneous code, we refine LLM-generated transformations by removing MR- irrelevant code elements with data-flow analysis. Finally, we assess candidate transformations based on encoded output relations and select the best transformation as the result. Evaluation results show that MR-Adopt can generate input transformations applicable to all experimental source inputs for 72.00% of encoded MRs, which is 33.33% more than using vanilla GPT-3.5. By incorporating MR- Adopt-generated input transformations, encoded MR-based test cases can effectively enhance the test adequacy, increasing the line coverage and mutation score by 10.62% and 18.91%, respectively.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑