如何在 运行 集成测试之前启动 spring-boot 应用程序
How to start spring-boot application before running integration test
我在我的 spring-boot 应用程序中使用 Gatling 插件来对作为应用程序的一部分公开的 REST API 进行性能测试,因此需要我的应用程序在 gatling 测试之前启动 运行秒。
由于默认情况下 Gatling 执行与集成测试阶段相关联,因此我尝试分别为预集成阶段和 post-集成阶段使用开始-停止目标,但同样出现以下错误:
[ [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] ]
只是添加 运行ning gatling 目标 mvn gatling:execute
运行 在应用程序启动时很好,但我想 运行 它作为 maven 阶段的一部分.
我用下面的代码让它工作。下面的代码将在您想要的配置文件中启动 spring 应用程序,然后继续 运行 您的测试。 ShutdownHook 将关闭服务。
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()
})
}
我在我的 spring-boot 应用程序中使用 Gatling 插件来对作为应用程序的一部分公开的 REST API 进行性能测试,因此需要我的应用程序在 gatling 测试之前启动 运行秒。
由于默认情况下 Gatling 执行与集成测试阶段相关联,因此我尝试分别为预集成阶段和 post-集成阶段使用开始-停止目标,但同样出现以下错误:
[ [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] ]
只是添加 运行ning gatling 目标 mvn gatling:execute
运行 在应用程序启动时很好,但我想 运行 它作为 maven 阶段的一部分.
我用下面的代码让它工作。下面的代码将在您想要的配置文件中启动 spring 应用程序,然后继续 运行 您的测试。 ShutdownHook 将关闭服务。
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()
})
}