Unit testing of Spring Boot Actuator endpoints not working when specifying a port

前端 未结 6 1916
忘了有多久
忘了有多久 2021-01-04 06:43

recently I changed my spring boot properties to define a management port. In doing so, my unit tests started to fail :(

I wrote a unit test that tested the /

6条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-04 07:36

    For Spring boot test we need to specify the port it needs to connect to.

    By default, it connects to server.port which in case of actuators is different.

    This can be done by

    @SpringBootTest(properties = "server.port=8090")
    

    in application.properties we specify the management port as below

    ...
    management.port=8090
    ...
    

提交回复
热议问题