Overview
portletUnit is a testing
framework used to test JSR-168 portlets outside portlet container just
as servletUnit is used to test servlets outside a servlet container.
The projected is architected to map the functionally of servletUnit
onto portlets with servletUnit itself providing the foundation for
portletUnit.
Getting Started
- Download
the latest distribution portletunit-0.2.3.zip
- Extract the zip file.
- Add lib/portletunit.jar to
the CLASSPATH
- Add jars/httpunit.jar to the
CLASSPATH. Do not use the standard httpunit jar.
- Add all other jars from the
jars directory to the CLASSPATH that are not already there.
At this point you can compile and test your portlet.
Sample Portlet Application
In the portlets/examples directory is a sample portlet
application. It contains 4 portlets that are used to do the
testing of portletUnit.
Writing a Test Case
The portletUnit test cases extend jUnit TestCase. A sample test
looks like:

- webInfDir points to the directory which contains the WEB-INF for
your portlet.
- runner is the actual portlet testing object. The two
arguments are:
- The directory which contains the WEB-INF directory
- The name of the portlet application. It comes from the
WEB-INF/web.xml where each portlet has a servlet definition. the
servlet definition must contain a portlet-guid and the application name
is the first half of the portlet guid.
- user is optional and defines the user who is currently logged
into the portal.
- runner.getResponse exceutes the portlet and returns the HTML it
generates.
Dependencies
All of these jar fails are found in the jars directory.
httpUnit
- Tidy.jar
- httpunit.jar (modified)
- js.jar
- nekohtml.jar
- servlet.jar
- xercesImpl.jar
- xmlParserAPIs.jar
- servletunit.jar
Apache Jakarata Commons
- commons-collections-3.1.jar
- commons-logging-api.jar
jUnit
Apache Pluto Portal
- castor-0.9.5.jar
- jasper-compiler.jar
- jasper-runtime.jar
- pluto-1.0.1-rc1.jar
- plutoImpl.jar
- portlet-api-1.0.jar