Corrections from Christian Bauer and Cedric Beust on my comments on TestNG

I have to get my comments feature working on my blog app (BBWeblog). Christian Bauer and Cedric Beust both emailed me with corrections to my blog entry about Christian’s comments on using TestNG for testing beans developed using JBoss’ EJB3.0 implementation.

Cedric said:

I just read your post about TestNG and EJB3 and I have a few thoughts.

Indeed, TestNG is not just about unit testing. The idea behind TestNG is the realization that mocks and unit tests (testing one class in isolation of all others) only get you so far. At some point, you really need to test what is actually going into production, and if it means making real database modifications and displaying real HTML pages, so be it.

The main feature that got Christian excited, though, is not exclusively an integration feature: test groups. Once you get used to them, you just can’t live without them.

Another popular feature of TestNG is parameters: you can pass parameters to your test methods (which simplifies your testing code quite a lot, as you’ll find out) and the more sophisticated version of parameters: Data Providers (@DataProvider). Look them up in the documentation and let me know what you think!”

I need to spend some time and check out TestNG (maybe in future I should try things out for myself before I make comments… :0 )

Christian Bauer also emailed me and wanted to make a couple of clarifications to the points I made:

He is currently 95% complete with the mapping chapters, but still has a way to go on the last third of the book, so it doesn’t sound like we’ll be seeing it soon.

– You need the EJB3 container (which starts in 2 seconds on my machine) to do integration testing. You don’t need it for unit testing.

– You can test EJB3 beans without a runtime container. Just instantiate them and call a method, they are POJOs.

– TestNG can do whatever you like, it is not bound or tied to anything. It just happens that it makes integration testing very easy, something JUnit makes very difficult.”

I think I missed the main point that Christian was making in his article. TestNG, as well as being a unit testing framework, can also be used to integration test EJB3.0 beans when running in container. I lost sight of the point that EJB3.0 bean are still POJOs, and can still be tested outside the container using a framework like TestNG or JUnit. This is a huge benefit and a huge change from 2.x days. Thanks for the comments guys.

J2EE without a container – yes it’s possible

I often wonder what proportion of Java developers make an effort to keep up with the latest developments and trends in the Java world. After all, things have been changing pretty quickly, and what was yesterdays accepted standard is todays antipattern.

There was a post on The Serverside this morning by a contributer who claimed he had found a ‘fundamental flaw in Java compared to .NET’, and then subsequently was flamed to within an inch of his life by the masses who were all too willing to let him know he was living under a rock.

His claim was that J2EE APIs are only available to Java applications running in a J2EE container. While this might have been true 5 years ago, it is definitely not true today. There are plenty of implementations of all the J2EE APIs that can be used out of container – his main example was JTA, the Java Transaction API. JOTM, Java Open Transaction Manager is a JTA implementation that is standalone and can be used by applications running outside an app server. Also, the major trend setter in this area right now is of course the Spring Framework – Rod Johnson and Co and done an awesome job convincing the Java community that there is an easier way to develop J2EE applications, avoiding the complexities and drawbacks of the J2EE approach but still retain usage of all the benefits.

With JBoss ploughing ahead with their implementation of the EJB3.0 spec, they even have (I believe) a version of their implementation that can be used outside of the JBoss App Server.

The point to my rambling is that it is all too easy to get trapped in a rut, and to become so focused on your current tasks that you become blind to what is going on outside of what you are doing. Spend some time each day to read some websites that are related to the area in which you work, and occaisionally some that are unrelated to the technologies in which you work to get a broader picture. It’s a dangerous trap to fall into to become oblivious to what is going on around you, and yet doesn’t take much effort to keep in touch with what is new and what is happening elsewhere.