Java Reference
In-Depth Information
stubs sufficient, but as you saw, this technique suffers some significant drawbacks.
That's why we cover the in-container testing approach deeper in the topic. Further-
more, this chapter focuses on the in-container testing methodologies by means of
one of the most popular in-container testing frameworks: Cactus. We start by intro-
ducing the Cactus framework and then show you some real-world examples of how
to use Cactus.
We begin by explaining what's so special about Cactus and the order of execution
of Cactus tests. We then build a sample application that uses some components from
the Java EE spec, and we write the tests for those components with the help of Cactus.
The next step is to execute those tests; we show a sample integration between Cactus
and some of the most popular build tools (Ant and Maven). But we go a bit further
than that: we demonstrate the tight integration between Cactus and other projects,
such as Cargo and Jetty. So let's start!
14.1
What is Cactus?
Cactus is an open source framework ( http://jakarta.apache.org/cactus/) fo r in-
container testing server-side Java code (mostly Java EE components in the current ver-
sion of Cactus). It's an extension of JU nit that was created by Vincent Massol in 1998.
Before we go any further, I'd like to clarify the definitions just mentioned. When
we say Cactus is a framework , we mean that it provides an API that you have to extend in
order to use it.
Also, in-container means that (as you'll see later in the chapter) the tests get exe-
cuted inside the virtual machine of the container. And finally, Cactus is an extension of
JU nit for two reasons: First, it extends JU nit by empowering it with new functionality
(Cactus makes JU nit tests get executed inside the container, something which other-
wise wouldn't be possible). And second, Cactus's API extends JU nit's API ; in low-level
software engineering terms, it extends some of JU nit's classes and overrides some of
JU nit's methods.
Let's see Cactus in action. In later sections, we explain in more detail how it works.
14.2
Testing with Cactus
This section is somewhat theoretical. You need this knowledge before you experiment
with a sample application, because Cactus is different from the normal unit testing
frameworks. Cactus executes the tests inside the container, which on its own raises a
lot of questions, so we try to answer all of them here.
14.2.1
Java components that you can test with Cactus
As we mentioned in the previous section, the Cactus project is used for testing the
core Java EE components ( JSP s, tag libraries, servlets, filters, and EJB s). What's worth
mentioning is that this is the only focus of the Cactus project. It doesn't test any spe-
cific framework (look at the next chapter if your application is framework specific),
because it isn't intended to do so. A lot of the emails that come from the Cactus
 
 
 
 
 
 
 
 
 
 
Search WWH ::




Custom Search