Do you have problems maintaining high test coverage? All code is guilty until tested innocent. Send the untested code to Guantanamo!
Guantanamo is a tool that can delete all code lines that are not covered by tests. It can also delete code that is not covered by the application itself. Guantanamo is part of the Extreme XP Tools family. Some thoughts about why it was created are written down here. 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, unreliable) code. It is defined like this:
<taskdef name="guantanamo" classname="org.codehaus.guantanamo.ant.GuantanamoTask"> <classpath> <pathelement location="lib/guantanamo.jar"/> <pathelement location="lib/xpp3-1.1.2a.jar"/> </classpath> </taskdef>
And used like this:
<guantanamo clover="target/clover/main/coverage-report/clover.xml" dest="target/clover/guantanamo"/>
Guantanamo Ant Task Documentation
Where to write the modified sources
Path to Clover XML Coverage file (clover.xml)
Path to JCoverage XML Coverage file (coverage.xml)
One and only one of these must be specified.
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
Removing code that may be run from the tests but isn't run from the app.
This is maybe one of the more instersting usages of Guantanamo. Just instrument your code with Clover or JCoverage (EMMA coming soon) and run the application in the normal way. When the application exits there will be coverage data about what is actually being used by the application. Try running Guantanamo over this coverage report. I'm sure you'll find something different than what you found from running it in conjunction with your tests. You may have to delete some tests that tested "orphan" code!
- Always leave guantanamoed code in a compiling state.
- Work with other coverage engines than Clover (which is the only supported one for now).
Guantanamo has hijacked Ashcroft's JIRA, where you can post patches, bugs and feature requests.
Q: Does the deleted code get deleted from the original sources?
A: No. The original sources are always left unchanged. Guantanamo writes the modified sources to a different folder that you have to specify. It's up to you if you want to transport them back to where they came from.
Q: What about good code without tests? Will it be taken away and sent to Guantanamo too?
A: Yes. We follow our own rules here. Your code has to prove its innocence through coverage. We don't have to prove that the code has bugs, we just assume it has. And therefore it must be taken away. It is for your own security.
Q: If good code is removed, doesn't this question the validity of Guantanamo itself?
A: You can't prove that untested code is good. Things that cannot be proven good must go.
Q: Have you considered that enforcing too strict XP policies on developers may turn them against XP as a whole?
A: Mind your own business, or we'll send your operating system to Guantanamo as well. If you're not with us, you're against us you sloppy waterfall coder! If it isn't 100% covered it is evil, evil, evil!
Q: Why did you choose such a bad-taste name?
A: What's bad taste - the name, or what's going on there? Would you rather look the other way and give the tool a nice name like "summer breeze"?