Joe Walnes
  Blog



Recent Entries

Creative uses of Hamcrest matchers

Hamcrest 1.1 released

Testing on the Toilet

Building testable AJAX apps (Does my button look big in this?)

QDox is back - 1.6 released

Java and .NET RESTful interoperability with XStream

I've joined Google

OSCon: SiteMesh, SiteMesh, SiteMesh, SiteMesh

Flexible JUnit assertions with assertThat()

SiteMesh and Content Management @ O'Reilly OpenSource Conference

XStream 1.1.2 released. Java 5 Enums, JavaBeans, field aliasing, StAX, and more...

VB.Net is the bestest

XStream 1.1.1 released

Accessing generic type information at runtime

XStream 1.1 released

JUnit tip: Setting the default timezone with a TestDecorator

XStream: how to serialize objects to non XML formats

How my backflip went...

Backflippin' in 4 hours.

Is 100% test coverage a BAD thing?

Looking back at the SiteMesh HTML parser

The road ahead for SiteMesh 3

Joe's Backflipping for Autistic Research - time is nearly up...

SiteMesh 2.2 Released

Advanced SiteMesh

More... [RSS | RDF]

About Joe Walnes

I am a software engineer for Google, based in London.

Open Source

WebStuff (coming soon)

XStream

ActiveMQ

SiteMesh

QDox

nMock

jMock

Pico Container

Nano Container

OpenSymphony

Squiggle

MockDoclet

MockObjects

Jelly

Groovy

PatternStitcher

XJB

Books

Java Open Source Programming, Wiley JSP Site Design, Wrox

Talks

Mock Roles, not Objects
October 26 2004, Vancouver, Canada. OOPSLA'04

Personal Development Practices Map
June 24 2004, Salt Lake City, Utah. Agile Development Conference

SiteMesh.NET and ASP.NET MasterPages
May 20 2004, Bangalore, India. Bangalore .NET User Group

Mock Objects: Driving Top Down Development
March 29 2004, St Neots, UK. OT2004

Mock Objects
December 2 2003, London, UK. XP Day 3


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.

Comments

Sam Newman

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

Robert Watkins

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. :)

Nat Pryce

The next step would be to change the toString method of the suite itself to return "A RowFilterApplier..." instead of "RowFilterApplierTest".

Ian Bourke

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

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.

Sam Newman

> 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

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();
}

Ross Mason

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 ;-)

Nick

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

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

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

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

penis enlargement

Hy, HAPPY NEW YEAR!!
Please, visit my site too. Thank you.

Name:
Email:
URL:

ThoughtBloggers

Martin Fowler

Dan North

Aslak Hellesoy

Darren Hobbs

Geoff Oliphant

Mike Roberts

Chris Stevenson

Jon Tirsen

Loads More...

Agile Bloggers

Ken Arnold

Ward Cunningham

Brian Marick

Robert Martin

Bret Pettichord

Java Bloggers

Ara Abrahamian

Mike Cannon-Brookes

Vincent Massol

Bob McWhirter

Rickard Oberg

Joseph Ottinger

James Strachan

Hani Suleiman

Communities

eXtreme Tuesday Club (XTC)

Thursday GeekSpeek

ThoughtWorks GeekNight

London Java Meetup

The Codehaus

[RSS | RDF]
© 2001-2004, Joe Walnes

Powered by SiteMesh and Moveable Type.