Solutions for Java developers
03/24/09
Use Cactus and Ant to test a Web application running inside
multiple Web containers
By Steven Haines
Software developers today have widely embraced test-driven
development (TDD) for the simple reason that tested code works
better. Furthermore, if you introduce new code into a working
application and it inadvertently breaks something, your test
cases will show you what specific functionality is broken and
where. For example, suppose your "test sorting with wildcards"
test case fails, stating that it expected 10 results from the
search string "happy*" but only 8 were returned. You know which
specific results are missing, so you know where to start your
investigations -- all from a test case that you might have
written a year ago!
TDD for more complex components such as servlets and Enterprise
JavaBeans, though, can be problematic, because these components
expect to run inside a container. Sure, you can build a mock
servlet or EJB container and test your code against the
specifications. That's a valid test that might be worth doing.
But a container's idiosyncratic behaviors might cause your
application to behave differently in different deployment
environments. This is a problem because TDD dictates that tests
be run automatically, whereas deploying an application to a
container and testing it with the granularity required of a unit
test is a cumbersome manual process.
Even if you use a solution for automatic deployment (such as
Cargo), unit-test-level granularity is still an issue. For
example, you can deploy an application to a container, execute
some piece of functionality, and then validate the results --
but that doesn't test internal servlet methods or examine
internal variables such as the session or servlet context to see
if variables are set appropriately. It only allows for external
"black-box" tests.
Jakarta Cactus provides a framework for testing servlets and
EJBs running inside different containers to obtain
unit-test-level metrics. You can determine not only whether your
application is returning the correct results, but also whether
the application is behaving correctly internally. This article
describes how to use Jakarta Cactus to write JUnit-style test
cases to test a Web application inside multiple Web containers.
You'll also learn how to automate your tests using Apache Ant,
which you can easily extend to be launched by a continuous
integration server like Hudson ...
Read more: How Cactus extends JUnit for the server-side
http://www.networkworld.com/nljavaworldsente188428
Related:
1. Writing good unit tests, Part 1
http://www.networkworld.com/nljavaworldsente187286
2. Continuous integration with Hudson
http://www.networkworld.com/nljavaworldsente175389
3. Automated code reviews with Checkstyle, Part 1
http://www.networkworld.com/nljavaworldsente171875
By all indications IBM is in serious talks to buy Sun
Microsystems this week, an acquisition that would have long-term
impact on Java technology, products, and licensing. Learn more
about the potential impact of this once-in-a-lifetime (and some
say long overdue) deal:
1. IBM and Sun: Future of GlassFish, NetBeans, and JavaFX
http://www.javaworld.com/community/node/2635
2. Google's Dibona says IBM could be good for Java
http://www.networkworld.com/nljavaworldsente188429
3. How IBM + Sun merger would impact IT
http://www.networkworld.com/nljavaworldsente188430
Find more on this topic in JW News & Views
http://www.javaworld.com/news-reviews/
Also see: CEO Payday: What tech chiefs made in 2008 -- Jonathan
Schwartz http://www.networkworld.com/nljavaworldsente188431
Do you need a degree to be a great programmer?
http://www.javaworld.com/community/node/2651
-There MAY be some genuinely talented programmers out there who
have no degree and are largely self taught, but they are few and
far between. Mostly what you get are cowboys ...
-The best programmers I have hired and worked with have college
degrees. The odd thing is I can't think of one with a CS degree.
-If I ever become a manager I'll be the first one to eliminate
the college degree requirement! (but it won't stop me from
getting MY degree)You've hit the tip of the iceberg: Read more in JW Blogs
http://www.javaworld.com/community/
_______________________________________________________________
This newsletter is sponsored by Dell
Safe and Secure Hardware Asset Recovery
Dell can help corporations to properly dispose of old PCs in a
secure and cost-effective manner that is also environmentally
friendly.
http://adserver.fattail.com/redir/redirect.asp?CID=292831
_______________________________________________________________
What you need to see all 7 layers
Get all the tools you need to see all 7 layers of your network. Fluke's OptiView Analyzer combines protocol analysis, active discovery, and device and traffic analysis in a mobile solution, giving you the information you need to control your network and minimize disruption. http://www.nww.com/rpgx.jsp?c=XU1PTA7013Z4155
Click here for your free trial.
_______________________________________________________________
This Newsletter Subscription Compliments of: Linuxworld.com http://www.linuxworld.com
ALSO FEATURED ON JAVAWORLD
Writing good unit tests, Part 1: Follow your GUTs
http://www.networkworld.com/nljavaworldsente187286
What do you know about the quality of your unit tests? Probably
not as much as you know about your production code. Klaus Berg
explains why craft matters just as much for test code as for
production code, then provides a comprehensive listing of agile
tools and best practices for improving the quality of your unit
tests.
ActionScript for Java developers, Part 2
http://www.networkworld.com/nljavaworldsente186633
Like other dynamic languages, ActionScript has capabilities and
usage patterns that could take a Java developer by surprise. In
this second half of his guide to the differences between Java
and ActionScript 3, Chet Haase discusses properties, dynamic
behavior, and functions.
Write your own Twitter app
http://www.networkworld.com/nljavaworldsente186081
Catch the social-networking wave with the convenience of Java
APIs. Using Apache Commons HttpClient, dom4j, and iText, create
a servlet-based application that dynamically archives Twitter
updates in a PDF document mirroring Twitter's look and feel.
Java concurrency with thread gates
http://www.networkworld.com/nljavaworldsente185460
The thread gate pattern is an effective tool for managing thread
concurrency, but not many developers know about it. Fire up your
IDE for a quick tutorial in implementing thread gates in
multithreaded business applications.
_______________________________________________________________
This newsletter is sponsored by Dell
Safe and Secure Hardware Asset Recovery
Dell can help corporations to properly dispose of old PCs in a
secure and cost-effective manner that is also environmentally
friendly.
http://adserver.fattail.com/redir/redirect.asp?CID=292831
_______________________________________________________________
UPCOMING ON JAVAWORLD
-Writing cloud-ready, multicore-friendly code, Part 2
-Jump into JavaFX, Part 4: Advanced APIs
-Understanding actor concurrency, Part 2
-REST for Java developers, Part 4
-Introduction to Spring MVC
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
What you need to see all 7 layers Get all the tools you need to see
all 7 layers of your network. Fluke's OptiView Analyzer combines
protocol analysis, active discovery, and device and traffic
analysis in a mobile solution, giving you the information you need
to control your network and minimize disruption.
http://www.nww.com/rpgx.jsp?c=XU1PTAZ4155 Click here for your free
trial.
_______________________________________________________________
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