Skip to end of metadata
Go to start of metadata

Download

svn co http://svn.codehaus.org/ashcroft/guantanamo

Introduction

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:

And used like this:

Guantanamo Ant Task Documentation

Property

Description

Required

dest

Where to write the modified sources

Yes

clover

Path to Clover XML Coverage file (clover.xml)

*

jcoverage

Path to JCoverage XML Coverage file (coverage.xml)

*

(star) 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 (smile)

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!

Goals

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

FAQ

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"?

  • No labels

9 Comments

  1. Anonymous

    The assumption behind this tool is that code is guilty until tested innocent, whereas in Camp Delta...... (wink)

  2. Anonymous

    "Code Is Guilty Until Tested Innocent" looks like the perfect t-shirt catchphrase for Guantanamo (smile)

  3. Anonymous

    The url http://builds.codehaus.org/public/project?project_name=Guantanamo doesn't work. "The requested URL /public/project was not found on this server."

  4. URL fixed. Now I need to fix DamageControl!

  5. Anonymous

    <i>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.</i>

    You also cannot prove that tested code is good. The only thing you can prove
    about it is that it passes some arbitrary test (of dubious quality).

    Moreover (and moving up a layer) the test code is, itself, untested. So, by your metrics it is not "proven".

    Tests have NOTHING to do with code quality. They simply test that something conforms to some "contract".

    Example:

    public String addTwoStrings(String a, String b){
    return "foobar";
    }

    Now consider this test method extract:

    String result = addTwoStrings("foo", "bar");
    AssertEquals(result, "foobar");

    The method would pass the test with flying colors.

    So there.

  6. Anonymous

    And if that's the entire body of the test for the addTwoStrings method, you're fired. Bye bye, thanks for playing! (smile)

    In general, it's a lot easier to write valid tests than it is to write code that implements the methods they test. Since writing tests to test the tests would be even harder than the original code, we rely on good coders to write good (relatively easy) tests that test the suspect (relatively difficult) application code.

  7. Anonymous

    I'm over my head with code, but there's an "instersting" that wants to be an "interesting," and where spelling is concerned, I'm not over my head.

  8. Anonymous

    How does it cope with "silly typed exceptions" like..

    public Object clone() {
      try

    Unknown macro: {    return super.clone();  }

    catch (CloneNotSupportedException e)

    Unknown macro: {    // checkstyle won't let me ignore this exception    throw new ItsAllGoneWrongRuntimeException(e);  }


    }

    Where's a human rights lawyer when you need one?

  9. Anonymous

    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"?

     And what IS going there? Do YOU know? Or do you just THINK you know, you smug little snot?

     Funny how your nice new tool (which is an interesting idea by the way) actually verifies what is going on, and takes action accordingly. It doesn't speculate, or act on what the guy on NPR SAYS is the code coverage. On the other hand, I'd hate to see what a tool called "Aslak" did to code - it would rush to judgment all over the place, no doubt deleting all sorts of useful code. You can guarantee that code "approved" by "Aslak" wouldn't even compile, let alone pass its unit tests!

    In all fairness, I do understand that there might be some temptation to inject your political views into your programming, but it's really something you should resist. A good rule of thumb would be, if you can't stop yourself snickering and smirking (like a nine-year-old hearing "fart" ) as you assign a name to a new project, then that name is inappropriate, and reflects your shallow and puerile assessment of geopolitics.

     I can't wait for your "BushIsSatan" application server...