Easy to Learn Java: Programming Articles, Examples and Tips

Start with Java in a few days with Java Lessons or Lectures

Home

Code Examples

Java Tools

More Java Tools!

Java Forum

All Java Tips

Books

Submit News
Search the site here...
Search...
 
Search the JavaFAQ.nu
1000 Java Tips ebook

1000 Java Tips - Click here for the high resolution copy!1000 Java Tips - Click here for the high resolution copy!

Java Screensaver, take it here

Free "1000 Java Tips" eBook is here! It is huge collection of big and small Java programming articles and tips. Please take your copy here.

Take your copy of free "Java Technology Screensaver"!.

Unit test your Java code faster with Groovy

JavaFAQ Home » Java Tools Go to all tips in Java Tools


Bookmark and Share

I'll start with a confession: I'm a unit testing addict. In fact, I just can't write enough unit tests. If I'm developing for long stretches of time without having written corresponding unit tests, I get the jitters. Unit tests give me the confidence that my code works and that I can change it, at a moment's notice, without the fear of it breaking.

Furthermore, as an addict, I tend to write a plethora of test cases. My high, however, isn't from writing the test cases; it's in seeing their results. Consequently, if I can write the tests in a rapid manner, I can view their results quicker. That way I feel better. Quicker.

Of late, I've been looking to Groovy to appease my unit testing addiction, and so far I'm impressed. The agility this new language brings to unit testing is quite exciting and worthy of some serious exploration. In this article, the first in a new series introducing the practical aspects of Groovy, I'll introduce you to the pleasures of unit testing with Groovy. I'll start with an overview of Groovy's unique contributions to development on the Java platform, then move on to discuss the particulars of unit testing with Groovy and JUnit, with special emphasis on Groovy's extension of JUnit's TestCase class. I'll conclude with a working example that shows you, first hand, how to integrate these groovy features with Eclipse and Maven.

No more Java purism!

Before I launch into the practical aspects of unit testing with Groovy, I think it's important to talk about the more general issue of its place in your development toolbox. The fact is, Groovy isn't the only scripting language that runs on the Java Runtime Environment (JRE), it's just the only one that has been proposed as a standard language for the Java platform. As some of you will have learned from the alt.lang.jre series (see Resources), there are myriad options when it comes to scripting for the Java platform, most of them presenting highly agile environments for rapid application development.

Despite this abundance of choices, many developers choose to stick with their favorite and most-familiar paradigm: the Java language. While Java programming is a fine choice for most situations, there is one very important shortcoming to wearing Java-only blinders. As a wise person once put it: If the only tool you have is a hammer, you tend to see every problem as a nail. I think there's a lot of truth to this saying that is applicable to software development.

Just as I hope to convince you with this series that the Java language is not and should not be your only choice for developing applications, it's also true that scripting languages make sense in some scenarios and not in others. What separates the professional from the tyro is knowing when to apply the power of scripting and when to eschew it.

For example, scripting is typically not such a good fit for high-performance, transaction-intensive, enterprise-wide applications; for these cases your best bet could be a normal J2EE stack. On the other hand, scripting -- and particularly scripting with Groovy -- can make a lot of sense when it comes to rapid prototyping of small, highly specific applications that are not performance intensive, such as configuration systems and/or build systems. It's also a near-perfect fit for reporting applications and, most importantly, unit testing.

Why unit test with Groovy?

What makes Groovy particularly appealing with respect to other scripting platforms is its seamless integration with the Java platform. Because it's based on the Java language (unlike other alternate languages for the JRE, which tend to be based on earlier predecessors), Groovy presents an incredibly short learning curve for the Java developer. And once that learning curve has straightened out, Groovy can offer an unparalleled rapid development platform.
All the article with details read here: A simple strategy for unit testing Java code with Groovy and Junit

On our site more about testing:

Improve Eclipse software development with robust logging plug-in
RAD Tutorial w/ JavaServer Faces and WS Portal
EditiX 2.1 - XML Editor & XSLT Debugger
A Look at Binary Runtime Environment for Wireless (BREW)
Use Rhino's Javascript graphical debugger with ITM on Linux and Unix
Annotations in Tiger (J2SE 5.0)
Visual Resource Bundle Inspector for Java
Demo Version of uCertify Exam Simulation PrepKit for Microsoft Exam 70-292 Relea

 Printer Friendly Page  Printer Friendly Page
 Send to a Friend  Send to a Friend

.. Bookmark and Share

Search here again if you need more info!
Custom Search



Home Code Examples Java Forum All Java Tips Books Submit News, Code... Search... Offshore Software Tech Doodling

RSS feed Java FAQ RSS feed Java FAQ News     

    RSS feed Java Forums RSS feed Java Forums

All logos and trademarks in this site are property of their respective owner. The comments are property of their posters, all the rest 1999-2006 by Java FAQs Daily Tips.

Interactive software released under GNU GPL, Code Credits, Privacy Policy