Home > Articles > Programming > Eclipse

Testing Java Enterprise Applications with Cactus

Marcus Zarra
  • PrintPrint
  • Share ThisShare This
  • DiscussDiscuss
Close WindowMarcus Zarra

Marcus Zarra

Learn more…

Marcus Zarra and Matt Long on Core Animation
Jun 5, 2009
Introduction to Migration in Apple's Core Data
Mar 7, 2008
A Look at Apple's Core Animation
Feb 1, 2008
The State of Java Development on OS X
Jan 4, 2008
Packaging Your Application for OS X
Nov 21, 2007
Tiger vs. Leopard: Which Should You Develop For?
Oct 26, 2007
Building on Apple Sync Services
Sep 8, 2006
Getting in Sync with OS X
Sep 1, 2006
Syncing Your Data the Cocoa Way
Aug 11, 2006
Controlling Both Ends of the Communications Channel: From Cocoa to Servlets
Jun 2, 2006
Cocoa: Working with XML
May 19, 2006
Java EJB 3.0: A Hibernate Clone?
Apr 28, 2006
Document Level Parameters Using Core Data: A Guide for Cocoa Developers
Apr 7, 2006
Tips for J2EE Development
Feb 24, 2006
The Cross-Platform Java GUI: Designing Code for More Than One Operating System
Feb 10, 2006
Avoiding Java Exception Abuse
Dec 22, 2005
Java Perspective: Advanced Core Data
Dec 16, 2005
Java Perspective: Cocoa-Java Bridge
Dec 1, 2005
Java Perspective: Core Data and the Mac OS X Developer
Nov 23, 2005
Java Perspective: Key-Value Protocols, Behind the Magic of Mac OS X Development
Nov 11, 2005
Java Perspective: Cocoa Subclasses and Delegates
Nov 4, 2005
The Java Perspective: Cocoa's Interface Builder
Oct 21, 2005
Maven: Handling Multiprojects
Sep 23, 2005
Java, Maven, and Your Web Development Project
Aug 26, 2005
Ant User, Let Me Introduce Maven
Jul 29, 2005
Using JAAS Authentication with JBoss
Jun 17, 2005
Building a Custom JBoss Login Module
Jun 10, 2005
Testing Java Enterprise Applications with Cactus
May 20, 2005
Ant: Building a Better Build File
May 6, 2005
XDoclet: Entity Bean Relationships
Apr 8, 2005
The Java Developers' Introduction to XDoclet
Jan 7, 2005
An Introduction to Cactus
Dec 30, 2004
Using Multiple Databases with JBoss
Nov 24, 2004
JBoss Application Configuration Breakdown
Nov 5, 2004
Sortable Swing JTable
Oct 1, 2004
Building a Professional Swing JTable
Sep 10, 2004
Creating a Custom Java Swing Tablemodel
Aug 27, 2004
Adding Workflow Control to Your Java Applications
Mar 26, 2004

Sorry, this author hasn't posted any blogs.

JUnit is great for both initial testing and regression testing as a project continues. But it doesn't provide support for testing local interfaces of Enterprise Java Beans or for testing the communication between servlets and EJBs. Marcus Zarra explains how Cactus comes to the rescue.

Cactus extends the functionality of JUnit and allows for the automatic testing of server-side components. Although this testing is normally limited to tag libraries and servlets, it is also possible to test local and remote interfaces to Enterprise Java Beans that use Cactus. Cactus is an open source project produced by the Apache Foundation and is part of the Jakarta Project. You can download Cactus here.

As discussed in my previous Cactus article, "An Introduction to Cactus," Cactus works very similar to JUnit and is in fact built upon JUnit. However, instead of each test being comprised of a single method, there are three methods for each test:

  • beginXXX—This method is executed from the "client" jvm and is intended to prepare a web request. A request object that will be used in the server-side call is passed into this method.
  • testXXX—This method is executed from the "server" jvm and runs in the same space as the servlets or server-side processes. This method is intended to execute methods on the servlet to test them.
  • endXXX—This method is executed from the "client" jvm and is intended to confirm results from the server-side processing.

These methods and this configuration can be utilized to test more than just tag libraries and servlets.

Issues with JUnit testing of EJBs

JUnit itself is an incredible tool for initial testing of Java code as well as regression testing of your code. Once you get into the habit of writing test cases for all your classes, productivity increases, and the quality of the code improves. When you have JUnit tests for all your classes, you can refactor your code and ensure that functionality is maintained.

An issue comes up when testing Enterprise Java Beans. To properly test them, you need to build the application, deploy it to the application server, and then execute the JUnit tests against the remote interfaces of the beans. This removes a lot of the automation from the testing, and (as we all know) the harder it is to test, the less testing will get done.

Cactus helps to resolve this issue. Because Cactus starts up the application server internally, there is no need to build and deploy the application prior to testing. By utilizing the client and server JVMs, it is possible to test both the local and remote interfaces for all the beans without having to do anything more than execute the ant task.

  • Share ThisShare This
  • Your Account

Discussions

Make a New Comment

You must log in in order to post a comment.

Related Resources

Danny KalevMinutes from the October 2009 Meeting
By Danny Kalev on November 19, 2009 No Comments

The minutes from the Santa Cruz (October 2009) meeting are available here. Even if you're not a language layer at heart, I encourage you to read them.

Danny KalevA Reader's Opinion on Attributes
By Danny Kalev on October 20, 2009 No Comments

In August I dedicated a series to the debate about C++0x attributes. I believe that it covered the subject in a balanced and detailed way, but I keep getting complaints from C++ users who don't like attributes for various reasons. Here's a recent email I received from a Polish C++ programmer. While it  doesn't represent my opinion about attributes -- I'm rather neutral about this feature and consider it a "solution waiting for a problem" -- but it suggests that attributes are still a highly controversial issue that will haunt C++ for a long time. The email is quoted here with minor edits that and as usual, with all private details removed.

Danny KalevFollowup: The Web 2.0 Guy I Ain't
By Danny Kalev on October 16, 2009 1 Comment

Almost a year ago, I posted here The Web 2.0 Guy I Ain't. People wonder whether I still resist all those Web 2.0 features and technologies at the end of 2009.

See All Related Blogs

Informit Network