user762421
user762421

Reputation: 537

How to start spring-boot application before running integration test

I am using Gatling plugin in my spring-boot application to do performance tests of the REST APIs exposed as part of the application hence need my application to be up before the gatling tests runs.

Since Gatling execution is associated to integration-test phase by default so I tried using start-stop goals for pre-integration-phase and post-integration-phase respectively but getting below error for the same :

[ [ERROR] Failed to execute goal org.springframework.boot:spring-boot-maven-plugin:1.5.1.RELEASE:start (pre-integration-test) on project : Spring application did not start before the configured timeout (30000ms -> [Help 1] ]

Just to add that running gatling goal mvn gatling:execute runs just fine when the application is up but i want to run it as part of maven phases.

Upvotes: 6

Views: 3305

Answers (1)

user6201420
user6201420

Reputation:

I got it working with the code I have below. The code below will start the spring application in the profile you want, and then proceed to run your tests. The ShutdownHook will turn the service off.

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()
  })

}

Upvotes: 8

Related Questions