一句话:提出内联测试,使开发者可在语句附近就地编写测试,并实现首个支持 Python 和 Java 的 I-Test 框架。
单元测试广泛用于检查代码质量,但粒度往往较粗,不适合测试单条程序语句。本文提出内联测试(inline tests),允许开发者在语句附近就地编写测试,例如直接测试正则表达式;同时给出与语言无关的内联测试框架需求。作者实现首个内联测试框架 I-Test,支持 Python 和 Java,并满足大部分需求。评估在开源项目中对 31 个 Python 程序和 37 个 Java 程序里的 144 条语句编写并运行内联测试,同时开展用户研究。九名参与者均认为内联测试易于编写且有益。运行开销仅为 0.007x–0.014x,可忽略不计;内联测试还发现两个已被开发者修复的缺陷。
Unit tests are widely used to check source code quality, but they can be too coarse-grained or ill-suited for testing individual program statements. We introduce inline tests to make it easier to check for faults in statements. We motivate inline tests through several language features and a common testing scenario in which inline tests could be beneficial. For example, inline tests can allow a developer to test a regular expression in place. We also define language-agnostic requirements for inline testing frameworks. Lastly, we implement I-Test, the first inline testing framework. I-Test works for Python and Java, and it satisfies most of the requirements. We evaluate I-Test on open-source projects by using it to test 144 statements in 31 Python programs and 37 Java programs. We also perform a user study. All nine user study participants say that inline tests are easy to write and that inline testing is beneficial. The cost of running inline tests is negligible, at 0.007x–0.014x, and our inline tests helped find two faults that have been fixed by the developers.