Spurious line reported in coverage

Hi,

I have a suite of unit-tests operating on a suite of classes.

One class, that only contains static methods has 100% coverage _apart_ from the line with the class declaration.

Possibly the default ctor is considered to be defined on that line?  But the odd thing is I have another similar class and for that class the declaration line _is_ considered covered (no instances of either class are ever constructed).

At a first look the only difference between these two classes is that one has multiple static function members and the other only has one...  e.g.

class X   <--- uncovered
{
    ... one static method ...
}

class Y   <--- covered
{
    ... about a dozen static methods ...
}

I can easily ignore this, but it just strikes me as very odd, so I was wondering if there was any known explanation or standard work-around?

Regards,

Ian

3 comments
Comment actions Permalink

Actually "spurious" is the wrong word.  If the default ctor is on that line then it is correct to be uncovered.

It is the inconsistency that is odd...  that and it is annoying not to be able to get 100% coverage.

Ian

0
Comment actions Permalink

Seen it before in other coverage tools, they often mark the weirdest things as uncovered that can't be covered.
In this case it's a class declaration (not a constructor).
In the past I've seen tools that flagged lines of whitespace as uncovered, other tools that flagged Javadoc as uncovered.

It's a main reason I don't advocate the use of code coverage tools as code quality measurements. 100% coverage is often impossible and if it is possible it likely requires some very bad programming practices.
At best they can help find places that are missed in writing tests, at worst (and in my experience that's too often the case) departments and companies stare blindly at the coverage number, to the point where programmers are punished for not reaching 100% without ever wondering why.

0
Comment actions Permalink

Thanks,

I realise that line isn't a written constructor, but I was wondering whether any automatically generated code for the class, such as a default ctor, was nominally considered to be on that line...

I quite agree with you, coverage as a way of finding holes is more useful than as a brute measure of quality (especially as it is fairly easy to write a test that increases coverage but doesn't actually test anything more).

It is just my slightly obsessive tendency, wanting to reach 100% :-)

And it is odd that this class counts that line as missed but the other counts it as covered...

Ian

0

Please sign in to leave a comment.