Do you have problems maintaining high test coverage? Send the untested code to Guantanamo!
Guantanamo is a tool that deletes all code lines that are not covered by tests.
I hear you say but what if the removed code actually serves a good purpose? The answer is simple. You can't prove it! According to Guantanamo, all code is guilty until proven innocent. Innocence is proven by test coverage. Consider this sample coverage report by Clover:
Removing that untested code
Guantanamo has an Ant task that you can use to remove untested (in other words, unnecessary) code:
After you have run Guantanamo over your sources, you can run Clover over the guantanamoed sources again and see the wonders it has done. In the case of our example, it would look like the following:
Eating our own dog food
Guantanamo is eating its own dog food. When it came to a working state, I ran it over itself, just to discover that there were lots of lines of code that were never executed. They no longer exist. And Guantanamo is still working fine. In fact, it has 100% coverage
- Always leave guantanamoed code in a compiling state.
- Work with other coverage engines than Clover 1.1.1 (which is the only supported one for now).
Q: What if Guantanamo deletes code that is good, like untested code that actually serves a purpose?
A: You can't prove that it serves a purpose.