New to JaCoCo - Constructor coverage.

3,386 views
Skip to first unread message

stevewi

unread,
Oct 29, 2012, 10:03:48 AM10/29/12
to jac...@googlegroups.com
I am fairly new to JaCoCo and have just integrated it into my build process for a project I am working on.
I am currently using netbeans 7.3 beta on debian linux linux (wheezy) with JUnit 4.10.  
The netbeans project is not a maven project and as such I have manually altered the build.xml file to include the JaCoCo ant tasks and targets.
The build runs fine and is generating a coverage report as I would expect, but I have noticed a few funnies.
One thing is that if my classes are utility type classes that only contain static methods and do not have a constructors I do not get 100% test coverage.. Eg
 
public class Utils
{
   // NOTE no default constructor.
 
   public void static Method1()
   {
   }
 
   public void static Method2()
   {
   }
}
 
Is there any way to force the JaCoCo tool to ignore this?  Is this a bug or is the tool assuming that all classes have a default constructor ?
I don't particularly want to create a default constructor in the affected classes to get the coverage up as an instance of these classes
does not make any sense in my design as they are utility classes.
 
Many thanks for any feedback.
 
Steve Williams

Marc R. Hoffmann

unread,
Oct 29, 2012, 4:46:19 PM10/29/12
to jac...@googlegroups.com
Hi,

if you don't declare a constructor in source code the Java compiler will
create one for you. As JaCoCo works on class files only it reports this
constructor.

To avoid your API users to instanciate Utils it is a good practice to
add an private default constructor. Future versions of JaCoCo might
provide an option to filter out certain compiler artifacts, we created a
list of candidates:

https://github.com/jacoco/jacoco/wiki/FilteringOptions

Best regards,
-marc
> --

stevewi

unread,
Oct 30, 2012, 4:44:39 AM10/30/12
to jac...@googlegroups.com
Hi Marc
 
I thought the class code might be doing something like this.
Any ideas if or when these filtering options might be implemented into jacoco ?
 
Many thanks for your feedback.

Marc R. Hoffmann

unread,
Oct 30, 2012, 8:36:43 AM10/30/12
to jac...@googlegroups.com
Sorry, no ETA for this feature. As this is all spare time work I don't
expect filtering to come soon.

-marc

stevewi

unread,
Oct 30, 2012, 12:56:27 PM10/30/12
to jac...@googlegroups.com
Ok no worries, I have a work arround for the time being.
 
Many thanks.
Reply all
Reply to author
Forward
This conversation is locked
You cannot reply and perform actions on locked conversations.
0 new messages