Making JUnit friendlier to AgileDox

Here’s a little trick to make JUnit display your test results in a similar way to AgileDox.

Override TestCase.getName() in your unit test…

public String getName() {
return super.getName().substring(4).replaceAll("([A-Z])", " $1").toLowerCase();
}

… and your test runner results are transformed from this …

… to this …

To make this easier, stick it in an abstract TestCase and inherit from that instead.

  • Trackback are closed
  • Comments (12)
  1. Its nice to have easily generated descriptions, but isn’t working with such long method names sometimes a pain? And couldn’t you achive something similar using JavaDoc and your own doclet? I suspect it would be more work than TestDox though (which I’m guessing just uses some class introspection and a bit of string parsing).

  2. Why would such long method names be a pain for test cases? It’s not like you ever call the test methods by hand, after all?

    In any case, with a modern IDE and auto-completion, long names only become a problem because of how long they make your lines of code. :)

  3. The next step would be to change the toString method of the suite itself to return “A RowFilterApplier…” instead of “RowFilterApplierTest”.

  4. Or just use the TestDox IntelliJ plugin, and get all of this for free with no work.

    http://www.sourceforge.net/projects/agiledox

    • Joe Walnes
    • January 30th, 2004

    Sam,

    By naming tests in this way, you can autogenerate a description of the responsibilities (or the contract) of the class under test. This complements the API to provide a clear description of what the class does.

    Of course, this can also be achieved by writing JavaDoc, except it has the added advantage that it is live and testable.

    > isn’t working with such long method names sometimes a pain?

    Not really. They’re test method names so they are only ever written once. I never have to remember them as JUnit figures them out automatically using reflection.

    > And couldn’t you achive something similar using JavaDoc and your own doclet?

    Yes. This is how TestDox works (kind of). It uses QDox which is an awesome ;) alternative to JavaDoc for reading source code.

    This snippet is meant to complement TestDox. TestDox is used to explore code. This just makes test names easier to read from the JUnit test runner.

  5. > This snippet is meant to complement TestDox.
    > TestDox is used to explore code. This just makes
    > test names easier to read from the JUnit test
    > runner.

    Hmmm….I can certainly understand that. And thanks for the QDox pointer.

    • Rob Dawson
    • February 4th, 2004

    For the poor people out there on a pre 1.4 jdk (and ORO in their classpath)…

    public String getName() {
    Perl5Util perl5Util = new Perl5Util();
    return perl5Util.substitute(“s/([A-Z])/ $1/g”, super.getName()).toLowerCase();
    }

  6. On the subject of AgileDox, you could use FatCow to document your web-testcases. Right now we generate a nice report, but it’s not really documentation. It would be very easy to generate other reports from the test results.
    BTW the recursion problem is now fixed and will be in version 0.2 ;-)

  7. Sadly, this little hack breaks IntelliJ Aurora.

    It seems as though it uses the displayed name to synch with the source. If you apply this cool hack, IntelliJ no longer seems to scroll to source when you click on a given test method…

    :'(

    Use the testdox plugin instead (though its scroll-to-source seems to be broken in the latest builds of Aurora…)

    -Nick

    • Deryl Seale
    • March 2nd, 2004

    How do you use TestDox in IntelliJ? I installed the plugin, but when I select a test class and activate the TestDox window, it just says “No TestDox Available”. Is there something else I need to install?

    thanks.
    -d.

    • Mike Corum
    • May 12th, 2004

    I couldn’t get it to work either. I tried in both IntelliJ 3 and 4. I also tried with WebStart and just saying java -jar etc.. I can find no way in which this tool will work at all. I’ve also downloaded qdox and put the library everywhere I can think of to try to make it work. Any help would be much appreciated.

    Mike

    • Franck Rasolo
    • May 18th, 2004

    Mike,

    Try the patched TestDox JAR that I posted on the IntelliJ Plugins forum:

    http://www.intellij.net/forums/thread.jsp?forum=18&thread=87116&message=1980626&tstart=0&trange=1001980626#1980626

    Hope it works for you!

    Franck

Comments are closed.
<span>%d</span> bloggers like this: