Vladimir Kruglov
Vladimir Kruglov

Reputation: 298

Java test project for integration tests

I have to work with some old java application. There is a total of 6 projects which:

As part of this:

  1. mvcMock mocks are used for the initial requests from test
  2. additional http requests are made by services and
  3. they go against dev server instead of calling code from current build;
  4. it'll fail if my test use code which communicates with another project by new endpoint which dev do not have yet.

How I thought of testing this

My idea was to use single test project which will run all required projects using @SpringBootTest and mockmvc to mock real calls and transfer them inside test instead of using real endpoints.

The ask

  1. I don't get how to make Spring to work with @Autowired and run 6 different WebApplicationContext's.
  2. Or maybe i should forget my plan and use something different.

Upvotes: 0

Views: 799

Answers (1)

Mark Bramnik
Mark Bramnik

Reputation: 42551

When it comes to @SpringBootTest its supposed to load everything that is required to load one single spring boot driven application.

So the "integration testing" referred in Spring Boot testing documentation is for one specific application.

Now, you're talking about 6 already existing applications. If these applications are all spring boot driven, then you can run @SpringBootTest for each one of them, and mock everything you don't need. MockMvc that you've mentioned BTW, doesn't start the whole application, but rather starts a "part" of application relevant for web request processing (for example it won't load your DAO layer), so its an entirely different thing, do not confuse between them :)

If you wan't to test the whole flow that involves all 6 services, you'll have to run a whole enviroment and run a full-fledged system test that will be executed on a remote JVM. In this case you can containerize the applications and run them in test with TestContainers.

Obviously you'll also have to provide containers for databases if they have any, messaging systems, and so forth.

All-in-all I feel that the question is rather vague and lacks concrete details.

Upvotes: 1

Related Questions