Java Reference
In-Depth Information
15.3.1. Project configuration
Before getting into the code for the integration test, you first need to set up and configure
the project to run it. To do this, the first question you need to answer is where the code for
the integration test will live. The convention for a unit test is to include it in the same pro-
ject as the class it's testing, because unit tests are quick and easy to execute and are the first
line of defense to check if code changes break anything. But where do you put integration
tests?
Integration tests will usually require a lot more complex configuration, and because the
tests will be running in an embedded container, they usually will require a lot longer to
run. Because of their complexity and time needed to run, integration tests are typically put
into their own projects. This is what you're going to do for this integration test example.
The code for this chapter contains a Maven submodule named chapter15-ejb-
embedded-test , which is where you'll put the integration tests that use the embedded
EJBContainer .
Will my integration tests ever run?
If you put your project's integration tests in a separate project, a common concern is wheth-
er the tests will ever get run. Unit tests inside a project are executed by Maven by default.
But if the integration tests are in a separate project, a developer will need to take an extra
manual step to run the tests, and most of the time this step will be skipped.
This is where tools like Bamboo, Jenkins, and other automatic build platforms come in.
The best practice is to configure these tools to run the integration tests automatically once
changes to the project have been detected. Alternatively, instead of doing them on demand,
they can be scheduled to run off hours, typically in the evening.
By using tools like this, you remove the responsibility of running the integration tests from
the development team and put it onto the tool. But if integration tests fail, then it becomes
the developer's responsibility again.
Now that you've decided that the integration test code will live in its own project, we'll
look at how to configure the project. The EJBs you want to test are in the Maven submodule
Search WWH ::




Custom Search