Can fully covered code have an EclEmma coverage rating of less than 100%?
Asked Answered
C

3

5

I just wrote some simple sample code to make sure that I had EclEmma installed correctly. I'm not getting 100% coverage, and I don't understand why. The highlighting implies that it has to do with the class name. Here's my code, with corresponding JUnit tests, the way EclEmma highlighted it:

Arithmetic class

Tests for Arithmetic class

The coverage results show that three instructions in Arithmetic aren't getting hit, even though both actual methods seem to be completely covered:

Coverage information

I've read the EclEmma documentation about basic block coverage, but I'm still confused. I'm not sure which basic blocks are being missed. At first, I thought EclEmma might just be ignoring the bytecode for classes, but ArithmeticTest seems to be handled just fine.

I have two closely related questions:

  1. Does this indicate a problem with the way I installed/configured EclEmma?
  2. Is it normal/acceptable for fully covered code to have a high-but-not-quite-100% EMMA coverage rating, and if so, how does that work?
Chlorate answered 8/6, 2012 at 15:27 Comment(0)
G
10

Your code implies a default constructor, which can't be properly tagged by Emma, because it doesn't have a block of text.

Since it is not properly tagged within the block of text, Emma can't associate the coverage logging with the text file, and it looks like some code isn't covered; because, you ran some bytecode, but the line logging couldn't be registered. Later when the reporting element reads the line logging, they can't find the line numbers for the default constructor, and it highlights the error in the only place that sort of makes sense, the class declaration line.

The default constructor looks like

public Arithmetic() {
  super();
}

Where the super is the implied first instruction which will construct Object. While you may omit its presence, the compiler will add it in for you. That's where your get "3 lines" instead of one.

Grover answered 8/6, 2012 at 15:31 Comment(1)
Actually, it does have a "block of text", it's just empty. In bytecode, the default constructor is there, at the line marked in red by EclEmma. To cover it and have it appear in green, a test just needs to call the constructor: new Arithmetic(). Of course, the correct thing here would be to declare a private default constructor in the class.Pounds
S
4

I think you will either need to test the instantiation of Arithmetic as well, or declare its constructor private to disallow instantiation

Sochi answered 8/6, 2012 at 15:30 Comment(1)
Ah, testing the constructor does it. EclEmma isn't any happier with a private constructor, but I think I remember seeing a workaround for that somewhere.Chlorate
A
2

IIRC, you need to instantiate an instance of the class to exercise the language provided constructor.

Anoxemia answered 8/6, 2012 at 15:30 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.