• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Improving code coverage

 
Ranch Hand
Posts: 104
2
Eclipse IDE Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I am doing unit testing for legacy code. When I have ran the code coverage tool, I see that very small part of code is covered by unit tests. I see that I have covered 100% for almost all public methods but code coverage is poor for other methods. What are the general guidelines that need to be followed to improve code coverage?

Thanks in advance,
Omkar V S
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are a few things you can do:
1) Look at the code to test more logic/paths through the private methods
2) Refactor the code to make it easier to test
3) Make some of the private methods package access to provide more entry points
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you have access to the legacy code(i.e. no decompilation restrictions) check to see if the public interface(class) can in various permissible(functionally) combinations generate better coverage results. If not check for data bounds check - very often the private methods act rarely, and most typically in these boundary conditions. If on the other hand these techniques don't work, just search by if-else, switch and ternary conditions(sometimes a very painful task, if code was written poorly and God classes / enthusiastic methods littter the code) and ensure you can manually create mocks which verify every line of behaviour/every flow path is visited.
 
reply
    Bookmark Topic Watch Topic
  • New Topic