Unit testing in Java vs. Smalltalk

By: on February 22, 2008

When you write unit tests, the minimal requirement before being able to try them out is that they compile. In Smalltalk, this means things like syntactic well-formedness, and perhaps the presence of global variables (i.e. classes) that you reference in the test method body.

It’s very quick and comfortable in Smalltalk to develop supported by unit testing: to write tests you know will fail, and refine away the failures until your test suite passes.

In Java, it’s much less comfortable, because besides the basic requirement of syntactic well-formedness, all the methods, classes, interfaces, and packages that your code relies on, directly or indirectly, must be present in the system before you can even try a run of the test suite! This makes for a less incremental style of development.

It would be very interesting to see a unit-testing framework for Java that simply treated a non-compiling test as a normal test failure, rather than a complete show-stopper, and which let you continue with the other tests in the suite. At the end of a run, it would include the non-compiling tests in the final reports just the same way as any other unexpectedly-failing test is reported.

FacebookTwitterGoogle+

4 Comments

  1. Neil says:

    Eclipse “compiles away” compile errors as runtime exceptions so running the tests inside Eclipse essentially gives you this for free.

  2. matthew says:

    I think you may want JMockObjects. Also, if you always write to interfaces rather than classes then this makes life easier too.

    Of course, really the type system should just carry around proofs and logical discriptions of what individual functions actually do and should know how these compose together.

  3. tonyg says:

    Matthew, I can see how interfaces remove some of the burden, but how would mock objects help? Also, all this hassle just to stop the compiler from simple-mindedly complaining about something I know I haven’t gotten around to yet… even using interfaces doesn’t fix the ergonomics of the system.

  4. tonyg says:

    Neil, it sounds like Eclipse is moving in the right direction. It’s a pity that lighter tools don’t work the same way.

    Give the Eclipse project another couple of years, and we’ll have a lovely greenspunned Strongtalk-a-like :-)

Post a comment

Your email address will not be published.

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>