|
|
|||||||||||||||||||||||||||||||||
Fabiano Cruz's BlogJUnit 4 youPosted by fabianocruz on June 11, 2006 at 03:01 PM | Comments (1)I think it's quite impressive how software testing has grown in popularity in the past decade. A lot of tools (open-source and commercial) and practices such as continuous testing and integration, code coverage, static analyzers and so forth. Some of that fancy stuff you've probably heard about, they were originated, disseminated and now getting lift from agile development processes "spaceship" (e.g.: Extreme Programming, Scrum and so on). But, the agile methodologies' boom is a topic for another talk. ;) In fact, as pointed out by Kent Beck in his presentation "TS-1580" at this year's JavaOne entitled "JUnit 4 and JavaTM EE 5: Better Testing by Design", we are now out of the Dark Ages and going into the Age of Paradox. According to Kent, in the Dark Ages (…just a few years ago), if you said to a developer, "you should write tests while developing your code", then most probably you could receive it as an answer: "You've gotta be kidding. Testing is for the QA folks". The Age of the Developer Testing Paradox (Today) is in the opposite sense, because we have a theoretical consensus which developer testing is a great idea and everyone should do it, but nevertheless, a practical reality: developer testing is still only practiced by a minority and testing is a low-status activity. Backing to JUnit 4 framework, which is the main topic of this blog, after 3 years or so without a significant release, they have come out with the version 4.0 which was officially announced in 2006-02-16 and didn't take so long for many leading vendors to start adopting it (see "JUnit 4 Ecosystem Support" table below – please, feel free to drop a line about your preferable IDE, tool etc, status regarding JUnit 4 support). So, the most popular and the de facto standard JavaTM unit testing framework, written by Kent Beck and Erich Gamma, became even simpler and it aims to provide an approachable (simple, easy-to-use, minimalist), flexible, responsive, extensible foundation for running and constructing solutions on top of it and to the ordinary person (this is important). I know that there will always be ways to improve frameworks like that, but I agree, it's really straightforward (thanks to JSR 175 - A Metadata Facility for the Java™ Programming Language and it is explicit metadata in the form of annotations and those who understood that testing is fundamental to software development, also thanks to NUnit and TestNG folks for the hard work on the test space).
(*) Partially supported – these tools are still improving their support regarding this new version of JUnit.
(**) for NetBeans 5.0/5.5 Beta and Eclipse 3.1.2 you must include the JUnit4TestAdapter which is part of the backwards compatibility strategy.
NOTE: JUnit4TestAdapter is not required for Eclipse 3.2. Some statistics from Sourceforge for JUnit project indicate that developers and companies in general seem to be more than convinced about the benefits of implementing unit tests: over 99% of activities and from ~17K in September 2003 (the announcement of version 3.8.1 which was a roll-up release for 3.8 with a couple of fixes) to ~66K (downloads/month) in the beginning of this year (version 4.0 announcement). In the JUnit 4 in 10 minutes article, Gunjan Doshi is revisiting the "old" JUnit (3.8.2 and its predecessors) showing the new features available in the version 4.0. He summarizes the new JUnit style:
We can also include the following annotations to the above list:
For instance, you can have both JUnit 3.x series and 4.0 coexisting in Eclipse IDE 3.1 and above. The following code illustrates how you can have both styles working together and also uses some of the new annotations presented so far:
One more example, but now showing parameterized test in JUnit 4 and also the
And, last but not least, JUnit 4.1 version has been announced in 2006-04-27 (it's a bug-fix release) and according to the information available here, the changes are:
Concerning the last change from the above list, the Enclosed runner is quite useful and you can find a simple example below:
Conclusion: In the past few years, we are seeing more and more programmers testing their own software and that's great. Writing unit tests doesn’t need to be boring or painful or frustrating, specially considering the huge JUnit ecosystem support, where fancy IDEs are providing nice mechanisms for developing tests. The JUnit 4 provides a clear, simple and extensible API for writing unit tests in Java. One important thing to say is that if you are currently planning to implement your tests using JUnit 4 style, please ensure that you have the support of the right tools, otherwise, you should keep going with JUnit 3.x series. Have fun! For more information:
Disclaimer: I don't claim to be an expert on testing. Please send comments and corrections. ;) Bookmark blog post: CommentsComments are listed in date ascending order (oldest first) | Post Comment
| |||||||||||||||||||||||||||||||||
|
|