How to start spring-boot application before running integration test

I use the Gatling plugin in my spring-boot application to run the REST API performance tests presented as part of the application, so I need my application to work before running the gatling tests.

Since the execution of Gatling is associated with the default integration-test phase, so I tried to use start-stop goals for the pre-integration and post-integration phases, respectively, but below the error for the same:

[[ERROR] Failed to fulfill the goal org.springframework.boot: spring-boot-Maven-plugin: 1.5.1.RELEASE: project start (pre-integration-test): Spring application did not start before the set timeout (30000 ms → [Help 1]]

Just add that the gatling running target mvn gatling:executeworks fine when the application is running, but I want to run it as part of the maven phases.

+4
source share
1 answer

I got it with the code below. The code below will launch the spring application in the desired profile and then continue to run your tests. ShutdownHook will disable the service.

class MicroserviceServiceSimulation extends Simulation {

  System.setProperty("spring.profiles.default", System.getProperty("spring.profiles.default", "it"));

  val app: ConfigurableApplicationContext = SpringApplication.run(classOf[YourApplication])

  Runtime.getRuntime.addShutdownHook(new Thread() {
    override def run(): Unit = app.stop()
  })

}
+6
source

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


All Articles