Annotations

Jitr provides annotations for you to use to have dynamic values and objects injected directly into your test class.

annotation expected type
@Port int
@BaseUri String

All fields marked with annotations must not have any of the following modifiers:

  • final
  • static

Options

All configuration is set using the @JitrConfiguration annotation. Some of these configuration values can be overriden from the command line using system properties.

parameter default system property description
containerClass JettyContainer.class n/a Which container you would like to run your integration tests with.
containerWorkPath target n/a The relative path to the working directory for the container.
contextPath / jitr.contextPath The context path of the web application.
mode OperationalMode.INTERNAL jitr.mode Specifies what Spring context configuration to use and whether or not to run a container. See below for more details.
port random, unused port jitr.port The port that the container should bind to. The default value or setting the port to -1 will cause Jitr to pick a random, unused port.
warPath src/main/webapp n/a The path to the war directory. For Maven projects the default value is correct.

Operational Modes

Jitr provides three different operational modes with each one catering to a differnt integration testing goal and execution mode.

Internal

Jitr runs the container and uses the same Spring application context as the running web application. This is the most common use of Jitr and was the intended target. This allows your tests to do things like use HSQLDB or some other in-memory database and setup your database from your tests before they run. You can share any bean instances you want from your web application with this mode, however you cannot (yet) specify any additional Spring context configurations to add or override the one from the running web application. Be aware that if no Spring application context is found in the running web application, Jitr will simply not try to wire your test (which means that Spring is not necessary to use Jitr). As is always the case, Jitr will also wire special port, base URI and container fields in your test should they exist and be properly annotated.

Mixed

Jitr runs the container and uses an external Spring application context. This can be useful if you don't need to share any bean instances between your web application and test class but still want to use Spring's auto-wiring feature.

This mode requires a Spring @ContextConfiguration annotation.

External

Jitr does not run the container and uses an external Spring application context. Similar to the above mode, this will let you use Spring's auto-wiring to setup your test class, however it assumes that you are starting and stopping the container manually or via something like Maven. Jitr will still inject the port and base URI if you set the necessary Jitr system properties.

This mode requires a Spring @ContextConfiguration annotation.

Containers

Jitr currently provides several containers for testing. All of these can be found in the org.jitr.container package. Jitr container wrappers are also easy to create on your own or you can choose to extend one of the above containers. Visit the Extensions page for more information.

Obviously there are more containers than are currently available in Jitr, so there are plans to make Jitr work directly with Cargo. Please visit the tracker issue for more details and for any status updates.