views:

100

answers:

1

I was trying to ignore all the toString() methods from instrumentation using following configuration. This wasn't really working? This is using cobertura as maven plugin. This was based on a previous answer http://stackoverflow.com/questions/951569/exclude-code-from-code-coverage-with-cobertura.

<instrumentation>
    <ignores>
        <ignore>toString</ignore>
    </ignores>
</instrumentation>

What do you think I'm doing wrong. I wasn't able to find an example for this on the cobertura documentation.

A: 

Have you tried using a "Base Object" that all your objects extend, which has an implementation of toString using Apache Commons' ReflectionToStringBuilder (a very useful api by the way)?

That way, you can just ignore all methods on the base object in a similar way to how the question you linked suggests.

Ben J
We do have an Eclipse generated #toString() method implemented in most of the objects, which has lots of if blocks to check instance variables for NULL before including them in the toString output. All of which conditions cobertura considers as separate branches bringing our coverage down.About every object extending a "Base Object", that just sounds inappropriate in OOPS sense.
chinto
Inappropriate? If you have an abstract base object that has (for example) a toString, hashCode and equals method (all implementable via the reflections API provided by Apache Commons) that stops you rewriting the same code over and over again (as you have done)... I'd say that's pretty useful.
Ben J
Extending one abstract class by all the hundreds of beans (Session/Entity/POJO) in the project doesn't sound too good. And sometimes I don't want to put every field in toString() like CLOB's etc. Anyway Let's not go off topic, I'm more trying to find out how to configure maven cobertura plugin to ignore some methods for branch coverage here.
chinto