End-to-end test testing across multiple Spring Boot applications

We are currently using Spring Integration in our project to integrate many services and some protocol-related endpoints.

The project is a multi-boot application Spring, in the process of deployment will be deployed several executable jars.

The question arises:

  • How to run the end-to-end test that needs to be done, cross-over some of these applications, do I have to run one by one manually? In cases where you are not running any Spring-Boot applications, I can use the Maven tomcat7 plugin to complete this work (deploy the wars in the built-in tomcat and run it in the pre-integration-test phase), now as for starting all related applications before starting the test. Suppose I am not using Docker / Vagrant right now.

    A similar question is found in stackoverflow, Integration Completion Test for Multiple Spring Boot Applications in Maven

    How to run end2end test automatically?

  • In the Spring Integration Test, once I had to make fun of the http endpoint, so I wrote a simple Controller in the test package to archive this target, but I want to run it on a different port, which make it more like an external resource. How to run different @SpringBootApplicaiton classes in different ports at the same time in the test for this purpose?

I am using the latest version of Maven, Java 8, Spring Boot 1.3.1.RELEASE.

Thanks.

+5
source share
1 answer

Actually, Spring Boot comes with support for embedded container support. One of them is for sure Tomcat. The default value for org.springframework.boot:spring-boot-starter-web .

With org.springframework.boot:spring-boot-starter-test and its @SpringApplicationConfiguration and @WebIntegrationTest you can achieve your requirements even with a random port .

See the Spring Boot reference guide for more information:

To change the port, you can add environment properties to @WebIntegrationTest as name and value pairs, separated by a colon or equal, for example. @WebIntegrationTest ("server.port: 9000"). In addition, you can set the server.port and management.port properties to 0 to run your integration tests using random ports.

In this case, your @SpringBootApplicaiton will be deployed for the built-in Tomcat, and your test can access the running services / controllers.

Note: it doesn’t matter if your Spring Boot application has Spring integration tools. The behavior is the same: built-in servlet tests and integration with @Value("${local.server.port}") .

0
source

Source: https://habr.com/ru/post/1240856/


All Articles