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

基于代码句法特征分布式表示的测试用例推荐

Test Case Recommendations with Distributed Representation of Code Syntactic Features

Northern Illinois University(北伊利诺伊大学)

Mosab Rezaei, Hamed Alhoori, Mona Rahimi

AI总结:

针对软件测试人工维护成本高的问题,提出基于代码和测试用例结构语义属性的分布式表示方法,通过余弦相似度匹配推荐测试用例,在Methods2Test数据集上验证可降低开发者工作量。

摘要:

软件的源代码、设计与需求持续发生底层变化,因此单元测试用例的频繁修改不可避免。由于人工维护软件测试套件繁琐、耗时且成本高昂,实现测试单元生成与维护流程的自动化将显著提升软件测试流程的效果与效率。\n为此,我们提出一种自动化方法,该方法同时利用源代码方法和测试用例的结构与语义属性,向开发者推荐最相关、最实用的单元测试。该方法首先训练一个神经网络,将方法级源代码以及单元测试转换为分布式表示(嵌入向量),同时保留代码中结构的重要性。在获取给定方法的语义与结构属性后,该方法计算该方法的嵌入向量与此前已嵌入的训练实例之间的余弦相似度。进一步地,模型根据嵌入向量间的相似度得分,识别出嵌入最接近的方法及关联的单元测试,作为最相似的推荐结果。\n在Methods2Test数据集上的结果表明,尽管无法保证相似方法组都存在对应的相关测试用例,但该方法能够为数据集中的给定方法提取出现有最相似的测试用例;评估显示,推荐的测试用例能够减少开发者生成预期测试用例的工作量。

英文摘要:

Frequent modifications of unit test cases are inevitable due to software's continuous underlying changes in source code, design, and requirements. Since manually maintaining software test suites is tedious, timely, and costly, automating the process of generation and maintenance of test units will significantly impact the effectiveness and efficiency of software testing processes. To this end, we propose an automated approach which exploits both structural and semantic properties of source code methods and test cases to recommend the most relevant and useful unit tests to the developers. The proposed approach initially trains a neural network to transform method-level source code, as well as unit tests, into distributed representations (embedded vectors) while preserving the importance of the structure in the code. Retrieving the semantic and structural properties of a given method, the approach computes cosine similarity between the method's embedding and the previously-embedded training instances. Further, according to the similarity scores between the embedding vectors, the model identifies the closest methods of embedding and the associated unit tests as the most similar recommendations. The results on the Methods2Test dataset showed that, while there is no guarantee to have similar relevant test cases for the group of similar methods, the proposed approach extracts the most similar existing test cases for a given method in the dataset, and evaluations show that recommended test cases decrease the developers' effort to generating expected test cases.

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

↑