0

I have created a rest application using spring-boot 2.0.3. From an other maven module (in a different multi module pom), I have an integration test that tests that data sent to the running rest application is processed.

Is it possible to run this spring-boot application programatically? I cannot use the simple @SpringBootTest-annotation as the spring-boot application is not in the same maven multi module.

jactor-rises
  • 2,395
  • 2
  • 22
  • 44

2 Answers2

0

I would recommend using mockito to mock a request to your rest endpoint with some data, and testing that your other application tries to send the correct data to the endpoint.

This way both applications are tested independently and do not have dependencies at each other. This provides the benefit of being able to substitute one of these applications with another if necessary. Also it provides a good separation. This is important because when you (or someone else) wants to use your REST application they do not use your other application so it is very important that the REST application is tested with static data written in your tests and is not dependent on the output of another application. Since REST applications are meant to be independent.

However, when you do want to test it this way you could try to include your other application in the classpath.

Sven Hakvoort
  • 3,543
  • 2
  • 17
  • 34
  • I have numerous tests which test the applications independently. But I would like to provide a single integration test that simply test that I can use the rest-application as intended so I can find configuration issues. I cannot depend directly on the application in a test scope (I have tried), but this is not feasible with a self contained spring-boot application – jactor-rises Jun 18 '18 at 11:21
  • In the way i explained you wont need numerous extra tests, only to do the integration test for the rest api itself without doing the test in your application. Since a rest application needs to be independent by definition. Or do you also dont want that? – Sven Hakvoort Jun 18 '18 at 11:22
  • I need to test the functionality of the main application, when it interacts with the rest application, it is mocked out... – jactor-rises Jun 18 '18 at 11:24
  • In that case mocking the rest api is definitely the best use case, following my answer above. But I understand you dont want that? And why? Because it should not create the need for numerous other tests – Sven Hakvoort Jun 18 '18 at 11:27
  • u misunderstand... I have unit tests which test the application and mocks the rest-application. but I would also like to have a single integration test to find any configuration issues... – jactor-rises Jun 18 '18 at 11:28
  • Ah ok, well according to my feeling and this source: https://stackoverflow.com/questions/7564038/how-are-integration-tests-written-for-interacting-with-external-api it is not a very good idea and should be done in the way i explained in my answer. – Sven Hakvoort Jun 18 '18 at 11:33
0

The thing is "loose coupling". It is technical possible, but not recommended. The build itself has numerous tests using where mocking with Mockito is essential.

An integration test module, ala cucumber.io, should be created which will cover the functionality of the running module.

This is the main-point of the accepted answer.

jactor-rises
  • 2,395
  • 2
  • 22
  • 44