简体   繁体   English

如何验证Spring Boot Web服务器是否正在运行

[英]How to verify that a spring-boot web server is running

I am writing an integration test for a spring-boot web server 我正在为Spring-boot Web服务器编写集成测试

I want to use junit-jupiter (junit5) to check if the server is running using Assumptions.assumeTrue so that the test do not fail if the server is not running... 我想使用junit-jupiter(junit5)使用Assumptions.assumeTrue检查服务器是否正在运行,以便在服务器未运行时测试不会失败...

There seems not to be any API support for such operation, but can it be achieved in some other way? 似乎没有任何API支持此类操作,但是可以通过其他方式实现吗? Pinging the server? ping服务器?

You could make use of the actuator module in spring boot. 您可以在弹簧罩中使用actuator模块。 It will provide you with a health check URL and you could make a call to this URL and verify that it returns healthy. 它将为您提供运行状况检查URL,您可以调用该URL并验证其是否恢复正常。

Now that that is out of the way, if you need the server to be running while running your tests, you should probably be using the spring boot test runner, instead of using the JUnit runner. 既然这样已经不成问题了,如果您需要在运行测试的同时运行服务器,则可能应该使用Spring Boot测试运行程序,而不是使用JUnit运行程序。 In this case you could still mock some of your spring beans and achieve the same kind of test, but with a spring context running alongside your tests. 在这种情况下,您仍然可以模拟一些Spring bean并完成相同的测试,但是在测试过程中同时运行spring上下文。 The downside of this is the overhead of needing to spin up the spring context before running tests, but if you need to use the actual web server, then this is what you should be doing. 这样做的缺点是在运行测试之前需要启动spring上下文的开销,但是如果您需要使用实际的Web服务器,那么这就是您应该做的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在没有 Web 服务器的 Spring-Boot 应用程序中,保持它运行的正确方法是什么? - In a Spring-Boot application without web server, what is the correct way to keep it running? Spring-boot Restful Web Service连接到ftp服务器 - Spring-boot restful web service connect to ftp server 将图像从 android 上传到 Spring-Boot Web 服务器 - Uploading image to a Spring-Boot web server from android 如何为嵌入在我的 spring-boot 应用程序中的 Web 服务器(Tomcat)配置低级套接字属性? - How to configure low-level socket properties for a web server (Tomcat) embedded in my spring-boot application? Spring-Boot:运行Spring Boot的Restful程序失败 - Spring-Boot: Failure on running of a spring-boot restful program 如何防止弹簧网的弹簧自动配置? - How to prevent spring-boot autoconfiguration for spring-web? 如何将Java代理附加到正在运行的Spring Boot应用程序 - How to attach a java agent on to a running spring-boot application starter-web 如何防止 spring-boot 退出? - How starter-web prevent spring-boot exit? 如何像在 web.xml 中一样配置 spring-boot servlet? - How to configure spring-boot servlet like in web.xml? 如何使用 OpenAPITools 创建 Spring-Boot REST 服务器 - How to Create a Spring-Boot REST Server Using OpenAPITools
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM