分支机构覆盖和断言覆盖? [英] Branch Coverage and Assert Coverage?

查看:93
本文介绍了分支机构覆盖和断言覆盖?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为大多数人现在都在使用分支机构覆盖率作为对语句覆盖率的质量度量,但是我没有太多了解的一个度量是:测试本身的质量。

I think most people are now using branch coverage as a quality metric over statement coverage, but one metric I've not seen much about is: the quality of the test itself.

例如,我可以编写测试代码中的许多分支的测试,但是没有一个测试可以断言。因此,尽管我执行了很多分支,但仍未正确检查退货条件。有什么方法可以捕获此断言指标?

For example, I could write tests which exercise many of the branches in my code, but none of the tests do an assert. So while I've executed a lot of my branches, I've not checked the return conditions properly. Is there any way to capture this "assert" metric?

人们是否在测试中使用了任何指标?

Are people using any metrics on the tests themselves?

推荐答案

博客文章 代码覆盖率的真正含义是什么? 涉及这个问题。研究结果表明,单元测试的代码覆盖范围通常是回归测试可靠性的良好指示。对于系统测试(执行大部分软件系统),代码覆盖率并不是可靠性的有用估算。

The blog post What does code coverage really mean? deals with this question. The study results indicate that the code coverage of unit tests is in general a good indication for the regression test reliability. For system tests (which execute large portions of a software system) the code coverage is not a useful approximation for the reliability.

突变测试可以用于评估测试用例的有效性。
的想法是通过引入错误来使源代码变异,并检查测试用例是否能够检测到错误。通常的方法是在一个方法上应用一个变异运算符(例如:删除一行代码,用减法替换加法,反转布尔条件),以运行所有测试并检查至少一个测试用例失败。失败的测试用例能够揭示出损坏的代码。突变测试的缺点是其计算复杂性以及等效突变体扭曲结果的问题(等效突变体是经过语法变异但在语义上保持不变的代码块)。 Pitest 是用于工业的Java突变测试系统。

Mutation testing can be used to evaluate the effectiveness of test cases. The idea is to mutate the source code by introducing faults and to check whether the test cases are capable of detecting the faults. The usual approach is to apply a mutation operator (eg: remove a line of code, replace an addition with a subtraction, invert a boolean condition) on a single method, to run all tests and to check if at least one of the test cases fails. The test cases which fail were able to reveal the broken code. The downsides of mutation testing are its computational complexity and the problem of equivalent mutants distorting the results (equivalent mutants are code chunks which were syntactically mutated but remained semantically unchanged). Pitest is a mutation testing system for Java which is used in industry.

对于不包含任何断言的测试用例,
Martin Fowler写道

Concerning test cases that do not contains any assertions, Martin Fowler writes:


尽管无断言测试主要是在开玩笑,但这并不是完全没有用的。 [...]一些错误(例如空指针异常)会通过代码执行来显示。

Although assertion-free testing is mostly a joke, it isn’t entirely useless. [...] Some faults [such as null pointer exceptions] do show up through code execution.

这篇关于分支机构覆盖和断言覆盖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆