Code clones are a well-known software quality metric with existing tools for detection and (semi-) automated elimination for common programming languages. While they are usually eliminated by extracting duplicate code into shared methods/functions, we are here looking in particular at Python code for test cases, where clones stem from repeated test cases with primarily different arguments and expected results. In this scenario, the ideal solution is not introducing shared code, but rather using parametrized tests from the unit testing framework. We combine an existing clone detector (NiCad) with our own code transformation that eliminates code clones in Python test cases using the pytest framework. We show the usefulness of our approach by surveying open source Python projects that can benefit from our refactoring and evaluate the performance and correctness of our transformation by comparing unit-test results before and after.

错误:搜索内容不能为空,请输入英文关键词
错误:关键词超出字数限制,请精简
高级检索

Automated Clone Elimination in Python Tests

  • Sebastian Kingston,
  • Violet Ka I Pun,
  • Volker Stolz

摘要

Code clones are a well-known software quality metric with existing tools for detection and (semi-) automated elimination for common programming languages. While they are usually eliminated by extracting duplicate code into shared methods/functions, we are here looking in particular at Python code for test cases, where clones stem from repeated test cases with primarily different arguments and expected results. In this scenario, the ideal solution is not introducing shared code, but rather using parametrized tests from the unit testing framework. We combine an existing clone detector (NiCad) with our own code transformation that eliminates code clones in Python test cases using the pytest framework. We show the usefulness of our approach by surveying open source Python projects that can benefit from our refactoring and evaluate the performance and correctness of our transformation by comparing unit-test results before and after.