How to start spring-boot application before running integration test
Asked Answered
H

1

6

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.

Horodko answered 5/2, 2017 at 14:50 Comment(0)
R
8

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

}
Rhetor answered 5/2, 2017 at 17:57 Comment(1)
Thank you thank you thank you thank you. I banged my head against this for a long time and your answer was a miracle.Ratter

© 2022 - 2024 — McMap. All rights reserved.