5

I using Jacoco as code-coverage plugin configured inside my pom.xml. I want to test and analyse coverage of only a few methods from my class file and want to show coverage percentage accordingly for them only. But as jacoco analyse whole file it shows less coverage, though the methods concerned are covered 100%. Is there any way out in jacoco to exclude some methods being analysed without changing source file code?

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
Deepak S
  • 1,544
  • 3
  • 15
  • 33

2 Answers2

4

That's not possible. Jacoco allows inclusions and exclusions at class level but not at method level.

There is some support for filtering at method level, discussed here. This allows Jacoco to ignore extraneous byte code generated by the Java compiler. On a similar note; Jacoco can also ignore some generated code on the basis of annotations (such as code generated by Lombok)

Although there is currently no way to tell Jacoco (via the Maven plugin, for example) to ignore specific methods, there are some open Jacoco issues related to this:

You could perhaps vote for those and/or raise another issues for your specific requirements.

glytching
  • 44,936
  • 9
  • 114
  • 120
0

It is not clear why you "want to test and analyse coverage of only a few methods from my class file and want to show coverage percentage accordingly for them only."

  • May be you have some code which is not related to main class? In this case think about design. One of possible solution is to split your class to parent and child or main class and some utilities.
  • May be 2 developers are working with the same class you each wants to show only own results?
  • May be some code hard to test? Try the mocking way.
Dmytro Maslenko
  • 2,247
  • 9
  • 16
  • we are in the process of migrating the old architecture code to web service architecture and from the old written service methods a few only got converted to web services till date , others are in process. So we want to check coverage of only those methods which are treated as web services. – Deepak S Aug 17 '17 at 02:00
  • These web service methods are using the old service code that is partially covered due to the mentioned fact that only a few of these old service methods are exposed via web services. – Deepak S Aug 17 '17 at 02:01
  • 1
    I believe parent-child way will help you not only in test coverage but in migration process too. You will have clear separation between old and new code. – Dmytro Maslenko Aug 17 '17 at 02:52