一句话:提出跨语言跨平台的人机协同单元测试迁移方法 MUT,复用测试并发现缺陷。
源代码级单元测试迁移长期缺乏探索。本文提出跨语言、跨平台的测试迁移方法 MUT,包含代码映射、测试用例过滤、测试用例翻译与测试用例适配四个模块:先建立源项目与目标项目的代码关联并筛选可迁移测试,再解析待迁移代码生成语法树并逐节点转换,最终在目标项目中编译执行;同时提供 Web 工具辅助开发者。作者在五个开源功能领域项目上迁移 550 个单元测试并提交 PR,其中 253 个已被合并;运行迁移测试发现 5 个 bug 与 2 个功能缺陷,表明该方法可行且有益。
Test migration, which enables the reuse of test cases crafted with knowledge and creativity by testers across various platforms and programming languages, has exhibited effectiveness in mobile app testing. However, unit test migration at the source code level has not garnered adequate attention and exploration. In this paper, we propose a novel cross-language and cross-platform test migration methodology, named MUT, which consists of four modules: code mapping, test case filtering, test case translation, and test case adaptation. MUT initially calculates code mappings to establish associations between source and target projects, and identifies suitable unit tests for migration from the source project. Then, MUT's code translation component generates a syntax tree by parsing the code to be migrated and progressively converts each node in the tree, ultima tely generating the target tests, which are compiled and executed in the target project. Moreover, we develop a web tool to assist developers in test migration. The effectiveness of our approach has been validated on five prevalent functional domain projects within the open-source community. We migrate a total of 550 unit tests and submitted pull requests to augment test code in the target projects on GitHub. By the time of this paper submission, 253 of these tests have already been merged into the projects (including 197 unit tests in the Luliyucoordinate-LeetCode project and 56 unit tests in the Rangerlee-HtmlParser project). Through running these tests, we identify 5 bugs, and 2 functional defects, and submitted corresponding issues to the project. The evaluation substantiates that MUT's test migration is both viable and beneficial across programming languages and different projects.