Solutions for Java developers
04/09/09
By Klaus P. Berg
When writing unit tests for a method (or a constructor) it's
important that you cover all boundary cases and possible inputs.
Some inputs will cause the method to throw an exception, and
you'll want to verify that output. There are two types of
exceptions:checkedandunchecked. Both are of interest when it
comes to properly unit testing a method.
Checked exceptions are for expected errors and should be dealt
with programmatically. Unchecked exceptions are mainly for
programming errors, and are derived from the
JDKRuntimeExceptionclass. Such exceptions should be allowed to
brachiate all the way up the class hierarchy and terminate the
test, because they usually indicate situations from which the
program is not meant to recover. However,
someRuntimeExceptionsubclasses,
likeIllegalArgumentExceptionorNullPointerException, may indicate
errors in method parameters handed over to the callee. Of
course, if such exceptions are part of the API contract, they
have to be checked with a unit test.
In the next sections I'll highlight some of the idiosyncrasies
of exception testing with JUnit 3.8.x, JUnit 4, and TestNG, and
also offer tips for resolving exceptions and failures in
callback methods, based on JUnit 4 ...
Read more: Checked and unchecked exceptions in JUnit and TestNG
http://www.networkworld.com/nljavaworldsente191096
1. Writing good unit tests, Part 1: Follow your GUTs
http://www.networkworld.com/nljavaworldsente187286
2. Groovy-power automated builds with Gant
http://www.javaworld.com/javaworld/jw-02-2008/jw-02-gant.html
3. Recipes to improve your Google Web Toolkit development
http://www.javaworld.com/javaworld/jw-04-2007/jw-04-gwt.html
More in JW Blogs: 5 movie quotes for software developers
http://www.javaworld.com/community/node/2752
By Dustin Marx
1. I've just sucked one year of your life away
2. The code is more what you'd call 'guidelines' than actual
rules
3. Takes a big man to admit when he's wrong. I am not a big man
4. It's not the years, honey, it's the mileage
5. I don't know, I'm making this up as I go
Find out where these quotes originated and get five more
http://www.javaworld.com/community/node/2752 1. Deadlock anti-patterns #2: Worker Aggregation
http://www.javaworld.com/community/node/2747
2. Deadlock anti-patterns #1: No Arbitration
http://www.javaworld.com/community/node/2701
3. 28 interview questions you wish you'd asked
http://www.javaworld.com/community/node/2745
4. Agile tactics: Refactoring on @Ignore
http://www.javaworld.com/community/node/2741
You've hit the tip of the iceberg: Read more in JW Blogs
http://www.javaworld.com/community/
_______________________________________________________________
This newsletter is sponsored by Avaya
Mastering UC: A Law Firm's Example
In this live webcast, the CIO of one of the largest, U.S.-based
intellectual property law firms talks about his experiences
implementing a unified communications solution. He'll describe
the challenges and resulting benefits, and how his firm has
mastered UC.
http://adserver.fattail.com/redir/redirect.asp?CID=294836
_______________________________________________________________
Complimentary DNS newsletter. Sign-up today and receive the latest
DNS news and analysis. This newsletter provides deep insight into
this murky area and offers ways to understand and mitigate risk
with better management and control of your domain, email and DNS.
Sign up now at http://www.nww.com/rpgx.jsp?c=XU1PTAZ4267
_______________________________________________________________
This Newsletter Subscription Compliments of: Linuxworld.com http://www.linuxworld.com
ALSO FEATURED ON JAVAWORLD
Jump into JavaFX, Part 4: The advanced APIs
http://www.networkworld.com/nljavaworldsente190628
Jeff Friesen completes his comprehensive tour of the JavaFX APIs
with a look at how JavaFX handles media, GUIs, and special
effects. You'll also try your hand at building and deploying a
stock-ticker application to Google Chrome.
REST for Java developers, Part 4: The future is RESTful
http://www.networkworld.com/nljavaworldsente190066
Find out why REST interfaces are foundational for emerging
architectures such as the Semantic Web. Brian Sletten takes a
big-picture view of REST, now and in the future, in this final
article in his series.
Lamport's one-time password algorithm
http://www.networkworld.com/nljavaworldsente189566
The Lamport algorithm provides an elegant scheme for generating
and applying one-time passwords, or OTP. Find out how Lamport
works, then see it in action with an OTP reference
implementation for an extensible, Java-based library.
Understanding actor concurrency, Part 2: Actors on the JVM
http://www.networkworld.com/nljavaworldsente188943
Erlang isn't the only language for implementing actor
concurrency. Find out how actors work and see them implemented
in Scala's standard library, Groovy's GParallelizer, and the
Java libraries Kilim, ActorFoundry, Actors Guild, and Jetlang.
_______________________________________________________________
This newsletter is sponsored by Avaya
Mastering UC: A Law Firm's Example
In this live webcast, the CIO of one of the largest, U.S.-based
intellectual property law firms talks about his experiences
implementing a unified communications solution. He'll describe
the challenges and resulting benefits, and how his firm has
mastered UC.
http://adserver.fattail.com/redir/redirect.asp?CID=294836
_______________________________________________________________
UPCOMING ON JAVAWORLD
-Cloud-ready, multicore-friendly code, Part 2
-Introduction to Spring MVC, Part 1
Podcasts:
-Alex Miller: Talkin' about Terracotta
-Make way for Jetty: Coming of age at 12
JavaWorld's Daily Brew - Starting conversations in the Java
developer community
http://www.javaworld.com/community
_______________________________________________________________
BONUS FEATURE
Everybody says "Do more with less!" But no one tells you how. We
will and it costs nothing to find out at IT Roadmap Conference and
Expo. Coming to 10 cities in 09 including New York in February,
Denver in March, Chicago in April.
http://www.nww.com/rpgx.jsp?c=XU1PTAZ3907 Register now, attend
free.
_______________________________________________________________
May we send you a free print subscription to Network World?
You've got the technology snapshot of your choice delivered at
your fingertips each day. Now, extend your knowledge by
receiving 50 FREE issues to our print publication. Apply today
at http://www.subscribenw.com/nl2
International subscribers click here:
http://nww1.com/go/circ_promo.html
_______________________________________________________________
SUBSCRIPTION SERVICES
To make newsletter subscription changes or cancellation, please
go to:
http://www.subscribenw.com/nl/login.jsp
To change your e-mail address, go to:
http://www.subscribenw.com/nl/eclogin.jsp
Subscription questions? Contact Customer Service by replying to
this message.
This message was sent to: athenssuthakar.javaupdates@blogger.com
Please use this address when modifying your subscription.
_______________________________________________________________
For advertising information, write Susan Cardoza, Associate
Publisher Online, at: mailto:sponsorships@nwfusion.com
_______________________________________________________________
JavaWorld is a trademark or registered trademark of Sun
Microsystems, Inc. in the United States and other countries, and
is used under license by International Data Group, Inc. All
other product names and trademarks used are the trademarks of
their respective owners.
Copyright 2009 JavaWorld.
http://www.javaworld.com