Integration tests for continuous delivery using docker

I am currently developing a product that provides REST APIs and which will eventually be hosted in the cloud.

My spring tech stack (boot, mvc, data, test, etc.) on top of maven. I have integration tests to test my API connected to a test database.

In order to better test my product in the same environment it will run in, I would like to use a container to test the integration. My goal would be to follow this continuous delivery process:

  • compile
  • run unit tests
  • create an app (jar) and deploy it to a central repository
  • create docker container using this archive
  • start the container (using spring boot)
  • run integration tests with a running container
  • run performance tests
  • if everything is ok, deploy this container to the central repository
  • Expand this same container to prod (just using different command line arguments).

The potential for this approach is that the same test phase of integrating containers into production seems to be ideal, right?

However, I don't know how to do this using the spring mvc tests that are in my source package. How can I use mockmvc to accomplish such a thing? How can it be flexible enough to run integration tests in development?

Has anyone tried this approach? Am I missing something here?

Thank you in advance

+3


source to share


2 answers


Spring MVC Test Framework (i.e. MockMvc

) may not be used to test a Spring web application deployed in a Servlet container.

In contrast, the main goal of the Spring MVC Test Framework is to provide first-class "support for testing client and server Spring MVC code through a fluent API." In addition, it "uses it DispatcherServlet

to process requests, thus approximating full integration tests without requiring the Servlet container to run."

The above text is from the Spring Framework Reference Manual.



Thus, Spring MVC Test Framework can only be used for integration tests outside the container. If you want to test a Spring based web application deployed in a Servlet container, you will need to use other frameworks like HtmlUnit, HttpUnit, Selenium, etc.

Hello,

Sam

+1


source


I am working on a demo code that covers most of the markers you noted except the last 3. And I just created a blog post: Integration Testing with Spring Boot, Postgres and Docker which links to a couple of bitbucket repositories for Postgres DB Docker images (images available in Docker Hub) and Spring Boot test demo.

Mostly a custom Spring TestExecutionListener implementation is used to hook into the test method lifecycle to manage pulling the Docker image, start / stop docker containers, before and after testing. It can use the same container for all integration tests, or it can run a new container for each test, it is configurable.



Best, Orlando

+1


source







All Articles