How to detect an undefined method?
anthony.flury
anthony.flury at btinternet.com
Sat Apr 2 09:28:25 EDT 2022
On 27/03/2022 15:59, dn wrote:
> What is code coverage?
> In the simplest words, code coverage is a measure of exhaustiveness of a
> test suite. 100% code coverage means that a system is fully tested.
Sorry, but that is a gross over-simplification.
100% coverage means that you have tested all of the branches in a given
module, or a given class; it absolutely does not mean it is fully tested.
For example I can write code and unit-test cases for a trivial piece of
code, and to achieve 100% coverage, but for the code to still fail on
invalid input data, or for the code to fail due to exceptions from
library code that my code doesn't handle.
To claim to be fully tested a piece of code has to be exercised against
*every* possible input and *every* single possible event from *every*
single source - that alone makes 100% testing impossible. If you think
logically about it, you can only test a very small fraction of all
possible test cases; the key is to pick those cases which represent a
good range of possible inputs and events (including both valid and
invalid data, exceptions, errors etc).
At best 100% coverage measure means that every branch through the code
has been executed at least once by your test cases. It doesn't prove
that your test cases are complete, or that your code takes into account
all possible occurrences - 100% coverage doesn't mean it is fully tested.
In terms of coverage, achieving 100% coverage is a laudable target, but
it is often either unachievable or not worth the effort; aiming to
achieve a high value (say > 80%) is sensible target.
If you achieve your high coverage count by doing black-box testing (ie.
by testing to the specification of code and thinking what can right and
what can go wrong), then the coverage is a more useful measure - if you
write your unit-tests by looking at the code, then all that a high
measurement means is that you are able (mostly) to read and understand
your own code.
--
Anthony Flury
*Moble*: +44 07743 282707
*Home*: +44 (0)1206 391294
*email*: anthony.flury at btinternet.com
More information about the Python-list
mailing list