code coverage highlights unused methods - What to do?

by Lucas T   Last Updated May 28, 2018 09:05 AM

I have been tasked to increase code coverage of an existing java project.

I noticed that the code coverage tool (eclemma) has highlighted some methods that are never called from anywhere.

My initial reaction is not to write unit tests for these methods, but to highlight them to my line manager/team and ask why are these functions there to begin with.

What would the best approach be? Write unit tests for them, or question why they're there?

Thanks in advance



Answers 2


  1. Delete.
  2. Commit.
  3. Forget about it.

Rationale:

  1. Dead code is dead. By its very description it has no purpose. It may have had a purpose at one point, but that is gone, and so the code should be gone.
  2. Version control ensures that in the (in my experience) unique event that someone comes around later looking for that code it can be retrieved.
  3. As a side effect, you instantly improve code coverage without doing anything (unless the dead code is tested, which is rarely the case).
l0b0
l0b0
May 28, 2018 08:58 AM

As Java is statically compiled, it should be pretty safe to remove the methods. Removing dead code is always good. There is some probability that there is some crazy reflection system which runs them in runtime, so check first with other developers, but otherwise remove them.

max630
max630
May 28, 2018 08:59 AM

Related Questions


Java 8 and conditional coverage

Updated December 02, 2016 08:02 AM



How do you unit-test code using graphs?

Updated April 10, 2015 19:02 PM