Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Single integration test for several Spring apps

I have two Spring applications which interact which each other via database and some AMQP:

  • web-application built on Spring MVC
  • Spring-Boot application

Each application has its independent context and properties files.

What is the proper way of writing single integration test for these two applications?

More specifically: I can merge this two applications in one maven project in order to have access to both of them.

  1. Is it possible to configure test contexts for both applications in one Spring test? At the moment I have no idea how to tell spring use different contexts for different applications in one test.

  2. Another purpose of this testing is also to obtain code coverage for these two applications. That is why I can not just start, say, Spring-boot application as separate process. Is it possible at all?

like image 777
Andremoniy Avatar asked Dec 06 '25 21:12

Andremoniy


1 Answers

Spring's test module brings up a single application context (take a look at the key abstractions section of the official documentation) per test so no, you cannot have multiple application contexts per test.

What you can have is a merged application context that imports both the Spring Boot and Spring MVC application's context; that way, you can test beans from both applications. However, this is probably not what you want to do and it's something I would recommend against - your tests will become almost worthless since making this approach work could probably entail some hacks and you will not be testing your applications realistically given that they will be deployed separately.

You should write per-application integration tests and measure coverage for each of them. If your application is relatively small, you can have an end-to-end testing module that would leverage Docker containers to create an environment similar to your production and verify that your applications correctly work together.

like image 164
Miloš Milivojević Avatar answered Dec 08 '25 14:12

Miloš Milivojević