Home > Guides > Plugin Developers Guide > JUnit Plugin |
The JUnit plugin provides integration with the popular JUnit unit testing framework.
This plugin provides a base StrutsTestCase
class that can subclassed for tests that work on Struts 2 components. It is used within Struts 2 itself to test core framework components and many bundled plugins. The class StrutsSpringTestCase
is also provided, to support testing of actions that use Spring as the object factory.
First, include the plugin your POM (if using Maven 2) under the test scope:
if you are using Spring, also add:
If you are not using Maven 2 to build and test your code, ensure the plugin jar and its dependencies (spring-mock and junit) are in the testing classpath.
Now, your JUnit tests can subclass the StrutsTestCase
class, which handles starting and stopping the Struts 2 framework:
This plugin doesn't support any global settings.
This plugin is meant to be used during unit testing, and not during runtime. Therefore, include it in your build's classpath, but do not deploy it to WEB-INF/lib
in your Struts 2 application.