5

I have a question. Requesting your help. We have a spring boot application and I have written integration tests without Mocks, instead with TestRestTemplate and @SpringbootTest.

So on local machine, when i execute the tests, they execute fine as i have given MyApplication.class inside @SpringbootTest It will startup the spring application context and execute the tests.

Till here everything is fine.

But we deploy this application on different test environments like qa,e2e,staging and then on production. So we have to execute the Jenkins Job for my integration tests against the above environments as an acceptance tests.

My Question over here is :

  • When I execute these tests on jenkins, the tests get executed on a Jenkins Slave machine(which is picked randomly among the available executors) and it will hit the end points (either qa or e2e or staging or production end points) and send rest requests and get the responses and validate. But the tests start up the application context on the jenkins slave and loads on a random port and will be available on the jenkins slave machine till the tests finish though I am not at all interacting with the application context( as i am hitting external test end points). Is there any option not to load the spring application context when I am trying to run tests against real test server and to load the application context when testing on local?

Please help.. I am kind of new to spring boot and got stuck here.

Thank you very much in advance

Nicomedes E.
  • 1,326
  • 5
  • 18
  • 27

1 Answers1

0

The answer is no if you want to use TestRestTemplate or RestTemplate and want it configured by Spring. You even have to set the webEnvironment of the SpringBootTest to RANDOM_PORT or DEFINED_PORT otherwise the context won't have the TestRestTemplate

If you are happy to configure it by hand than you won't need the SpringBootTest annotation and you won't have any Spring context.

TestRestTemplate is great for calling the current application on localhost as part of SpringBootTest. There are other alternatives for integration testing like RestAssured what won't need Spring for executing.

Gebezs
  • 696
  • 3
  • 9