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.


  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).
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.

May 28, 2018 08:59 AM

Related Questions

Java 8 and conditional coverage

Updated December 02, 2016 08:02 AM

Rerun unit tests affected by change

Updated January 30, 2019 10:05 AM