Using the Jetty Plug-in to Start a Web Application
Functional testing is usually harder than unit testing because functional testing
requires a complete execution environment. This requirement is
particularly tough to satisfy when you are testing a web application, as
you need to start your application in a Servlet container. This lab demonstrates how
to use the Jetty plug-in to start the web application from Figure 3-1, in the Jetty Servlet container. We selected Jetty because
it is a very fast container and a quality Jetty plug-in is available for
Maven.
Note
Jetty takes only a few milliseconds to start up.
How do I do that?
As shown in Figure
3-1, there is an acceptance subproject from which you will
execute your acceptance tests (otherwise know as functional
tests).
The web project that you used
earlier generated the WAR that you wish to test functionally. You need
to tell the Jetty plug-in to deploy this WAR. You do this by defining
a dependency in the acceptance
project's project.xml, and by
tagging the dependency with the jetty.bundle property:
<dependency>
<groupId>mdn</groupId>
<artifactId>qotd-web</artifactId>
<version>${pom.currentVersion}</version>
<properties>
<jetty.bundle>true</jetty.bundle>
</properties>
<type>war</type>
</dependency>Let's configure the Jetty plug-in so that Jetty runs on port 8081 (by default it runs on 8080). You achieve this by adding the following property in the project.properties file, in the acceptance/ directory:
maven.jetty.port = 8081
Start Jetty ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access