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.
翻译:单位测试被广泛用于检查源代码质量, 但是它们可能过于粗略或不适合测试单个程序语句。 我们引入了内线测试, 以便更容易检查语句中的错误。 我们通过几种语言特征和通用测试方案来激励内线测试。 例如, 内线测试可以让开发者测试常规表达式。 我们还定义了线内测试框架的语言- 不可知性要求 。 最后, 我们实施了第一个线内测试框架 I- Test。 Python 和 Java 的 I- Test 工作, 并且满足了大部分要求 。 我们通过在 31 Python 程序和 37 Java 方案中测试144个语句和37个 Java 程序来评估开源的I- Test项目。 我们还进行了用户研究。 所有9个用户研究参与者都说, 线内测试很容易写, 线内测试也有好处 。 运行线内测试的成本微乎其值, : 0. 007x- 0.014x, 而我们的线内测试有助于找到两个开发者确定的错误 。