Integration Testing with Arquillian and Tomee

How to create fast and lean integration tests has been a concern for me for some time.

I found that using Arquillian with remote containers is the fastest way for development phase, but for continuous integration purposes sometimes we have to use an embedded container. That does not mean it cannot be fast regardless.

Using an embedded Tomee container is very simple and with these simple guidelines you will be up and running in no time.

Maven Dependencies

For Arquillian tests with Tomee container you need the following Maven dependencies:

    <!-- project coordinates omitted-->
    <!-- standard properties -->


        <!-- javaee -->

        <!-- Unit testing -->

        <!-- Arquillian -->

Next we create an arquillian configuration file for tomee container to avoid port conflicts.

Arquillian Configuration

    <arquillian xmlns=""
        <container qualifier="tomee" default="true">
                <property name="httpPort">-1</property>
                <property name="stopPort">-1</property>

Save this file as arquillian.xml in src/test/resources directory.

… and finally we create the test class.

Test Class

public class HelloResourceTest {
    @Deployment(testable = false)
    public static WebArchive createDeployment() {
        return ShrinkWrap.create(WebArchive.class)
                .addClasses(RestConfiguration.class, HelloResource.class)
                .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");

    public void shouldSayHello(@ArquillianResource URL url) throws URISyntaxException {

        WebClient webClient = WebClient.create(url.toExternalForm()).path("rest/hello");
        JsonObject message = webClient.get(JsonObject.class);


Very straightforward. We create the deployment package. use testable=false to emulate sandbox testing and verify the result. The HelloResource returns a simple JSON message:

   "message": "Hello World"

That’s it. Powerful Integration testing with minimum overhead.

Written on May 4, 2017