Wednesday, July 22, 2009

What JVM Language Do You Write Tests In?

 
At a recent NYC Scala meetup, I got chatted up and basically was asked the following:

I know you've been writing multi-threaded testing API's in Scala, but we're still writing tests in Java, so do you know any good Java multi-threaded testing API's?


(As a matter of fact I do, but that's not the point of this post.)

I couldn't help but immediately feel very bad. I feel genuinely sorry. Overwhelmingly sorry, in fact. Why? Because people in this world are still writing tests using Java. So, I'm calling on people to help me build an argument that can be used by people still trapped in a cave writing tests in Java. Most of the rest of this post will be a rant to start generating ideas, I'll try to formalize the argument by reading comments and then put it into another post.

Random Ranting To Generate Ideas


Scala and Groovy and JRuby and Jython and Clojure and so many more are by far better alternatives for testing on the JVM, and some of them have been for a long, long time. I started testing using Scala almost two years ago. I submit that if you can't get your organization to switch your testing language, you should leave. It's not even production code!

You can still run your old tests anyway, even if just in your current runner. ScalaTest also gives you many alternatives for running all your old tests and new tests very easily in the same runner.

You might argue that now you have to maintain two different code bases, two different languages for your tests. Honestly, I say Come On!. First, the new code tests will be far easier to maintain than any new tests you would have written in Java. Second, were professional software developers. If you can't manage one extra directory of code, you probably shouldn't be in this business.

I think of more later.

Poll


Also, I'm creating a new poll. What JVM Language Do You Write Tests In? If you are reading this from a feed, you might have to click to get in: http://jackcoughonsoftware.blogspot.com/

2 comments:

  1. Hi Josh,

    I was actually about the same thing at my day job.

    Should I promote Scala or something else for testing? As much as I would love to promote Scala (and specs of course) for that, there are clearly high barriers on an existing project:

    -new language, which may please you but maybe not other developers. As tests needs to be a team culture, it is decisive that everyone buys in the language.

    -an evolving language (see scala 2.8 which may break existing code or have compiler bugs, things you don't meet very often in Java ;-)

    -new tools (you got to install a new plugin, or a new dev. environment). But I must say that the integration with the existing Java infrastructure really shouldn't be a big deal

    -some interoperability issues to solve (especially with some java code predating generics, you might have to write a few collection conversion classes)

    On the other hand, I realized that a great deal of the work to do (on my specific project) was to build:

    - more setup functionalities to be able to create "business" objects with less lines of code

    - more mocking functionalities, to be able to do as if the objects really lived on a server

    - more business matchers

    All this can be done more elegantly in Scala than in Java, but the bulk of the work is just creating and organizing all that stuff.

    That being said, once this is done, I think that another testing language really enhance your ability to write tests which are both readable and easy to write. *And* you get access to testing goodies such as ScalaCheck (and MultiThreadedSuite ;-) ).

    So eventually I would say that it really comes down to a cultural issue:

    - the team should like writing tests
    - the team should like picking up the best tools for what they do

    Eric.

    ReplyDelete
  2. This comment has been removed by a blog administrator.

    ReplyDelete