Skip to content
Skip to breadcrumbs
Skip to header menu
Skip to action menu
Skip to quick search
Quick Search
Browse
Pages
Blog
Labels
Attachments
Mail
Advanced
What’s New
Space Directory
Feed Builder
Keyboard Shortcuts
Confluence Gadgets
Log In
Dashboard
Ashcroft
Copy Page
You are not logged in. Any changes you make will be marked as
anonymous
. You may want to
Log In
if you already have an account. You can also
Sign Up
for a new account.
This page is being edited by
.
Paragraph
Paragraph
Heading 1
Heading 2
Heading 3
Heading 4
Heading 5
Heading 6
Preformatted
Quote
Bold
Italic
Underline
More colours
Strikethrough
Subscript
Superscript
Monospace
Clear Formatting
Bullet list
Numbered list
Outdent
Indent
Align left
Align center
Align right
Link
Table
Insert
Insert Content
Image
Link
Attachment
Symbol
Emoticon
Wiki Markup
Horizontal rule
tinymce.confluence.insert_menu.macro_desc
Info
JIRA Issue
Status
Gallery
Tasklist
Table of Contents
Other Macros
Page Layout
No Layout
Two column (simple)
Two column (simple, left sidebar)
Two column (simple, right sidebar)
Three column (simple)
Two column
Two column (left sidebar)
Two column (right sidebar)
Three column
Three column (left and right sidebars)
Undo
Redo
Find/Replace
Keyboard Shortcuts Help
<h2>Download</h2> <p>svn co <a class="external-link" href="http://svn.codehaus.org/ashcroft/guantanamo" rel="nofollow">http://svn.codehaus.org/ashcroft/guantanamo</a></p> <h2>Introduction</h2> <p><strong>Do you have problems maintaining high test coverage? All code is guilty until tested innocent. Send the untested code to Guantanamo!</strong></p> <p>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 <a class="confluence-link" href="/display/ASH/Extreme+XP+Tools" data-linked-resource-id="11675" data-linked-resource-type="page" data-linked-resource-default-alias="Extreme XP Tools" data-base-url="http://docs.codehaus.org">Extreme XP Tools</a> family. Some thoughts about why it was created are written down <a href="http://blogs.codehaus.org/people/rinkrank/archives/000844_poor_test_coverage_send_your_code_to_guantanamo.html">here</a>. Consider this sample coverage report by Clover:</p> <p><img class="confluence-embedded-image" src="/download/attachments/230400660/poorly-tested-coverage.png?version=1&modificationDate=1368898160973" data-image-src="/download/attachments/230400660/poorly-tested-coverage.png?version=1&modificationDate=1368898160973" data-linked-resource-id="230564935" data-linked-resource-type="attachment" data-linked-resource-default-alias="poorly-tested-coverage.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="230400660" title="null > poorly-tested-coverage.png"></p> <h2>Removing that untested code</h2> <p>Guantanamo has an Ant task that you can use to remove untested (in other words, unreliable) code. It is defined like this:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <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> </pre></td></tr></table> <p>And used like this:</p> <table class="wysiwyg-macro" data-macro-name="code" data-macro-default-parameter="xml" style="background-image: url(/plugins/servlet/confluence/placeholder/macro-heading?definition=e2NvZGU6eG1sfQ&locale=en_GB&version=2); background-repeat: no-repeat;" data-macro-body-type="PLAIN_TEXT"><tr><td class="wysiwyg-macro-body"><pre> <guantanamo clover="target/clover/main/coverage-report/clover.xml" dest="target/clover/guantanamo"/> </pre></td></tr></table> <h3>Guantanamo Ant Task Documentation</h3> <table class="confluenceTable"><tbody> <tr> <th class="confluenceTh"><p> Property </p></th> <th class="confluenceTh"><p> Description </p></th> <th class="confluenceTh"><p> Required </p></th> </tr> <tr> <td class="confluenceTd"><p> dest </p></td> <td class="confluenceTd"><p> Where to write the modified sources </p></td> <td class="confluenceTd"><p> Yes </p></td> </tr> <tr> <td class="confluenceTd"><p> clover </p></td> <td class="confluenceTd"><p> Path to <a href="http://www.cenqua.com/clover/">Clover</a> XML Coverage file (clover.xml) </p></td> <td class="confluenceTd"><p> * </p></td> </tr> <tr> <td class="confluenceTd"><p> jcoverage </p></td> <td class="confluenceTd"><p> Path to <a href="http://www.jcoverage.com/">JCoverage</a> XML Coverage file (coverage.xml) </p></td> <td class="confluenceTd"><p> * </p></td> </tr> </tbody></table> <p><img class="emoticon emoticon-yellow-star" data-emoticon-name="yellow-star" border="0" src="/s/en_GB/3278/15/_/images/icons/emoticons/star_yellow.png" alt="(star)" title="(star)" /> One and only one of these must be specified.</p> <p>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:</p> <p><img class="confluence-embedded-image" src="/download/attachments/230400660/poorly-tested-coverage-guantanamoed.png?version=1&modificationDate=1368898160940" data-image-src="/download/attachments/230400660/poorly-tested-coverage-guantanamoed.png?version=1&modificationDate=1368898160940" data-linked-resource-id="230564934" data-linked-resource-type="attachment" data-linked-resource-default-alias="poorly-tested-coverage-guantanamoed.png" data-base-url="http://docs.codehaus.org" data-linked-resource-container-id="230400660" title="null > poorly-tested-coverage-guantanamoed.png"></p> <h2>Eating our own dog food</h2> <p>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 <img class="emoticon emoticon-smile" data-emoticon-name="smile" border="0" src="/s/en_GB/3278/15/_/images/icons/emoticons/smile.png" alt="(smile)" title="(smile)" /></p> <h2>Removing code that may be run from the tests but isn't run from the app.</h2> <p>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!</p> <h2>Goals</h2> <ul> <li>Always leave guantanamoed code in a compiling state.</li> <li>Work with other coverage engines than Clover (which is the only supported one for now).</li> </ul> <p>Guantanamo has hijacked <a href="http://jira.codehaus.org/browse/ASH">Ashcroft's JIRA</a>, where you can post patches, bugs and feature requests.</p> <h2>FAQ</h2> <p>Q: <strong>Does the deleted code get deleted from the original sources?</strong><br /> 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.</p> <p>Q: <strong>What about good code without tests? Will it be taken away and sent to Guantanamo too?</strong><br /> 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.</p> <p>Q: <strong>If good code is removed, doesn't this question the validity of Guantanamo itself?</strong><br /> A: You can't prove that untested code is good. Things that cannot be proven good must go.</p> <p>Q: <strong>Have you considered that enforcing too strict XP policies on developers may turn them against XP as a whole?</strong><br /> 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!</p> <p>Q: <strong>Why did you choose such a bad-taste name?</strong><br /> 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"?</p>
Please type the word appearing in the picture.
Attachments
Labels
Location
Watch this page
< Edit
Preview >
Loading…
Save
Cancel
Next hint
search
attachments
weblink
advanced