I'm not sure when this started happening, but it appears that @SpringBootTest(webEnvironment = WebEnvironment.NONE) doesn't work correctly. For example, running smoketest.profile.ActiveProfilesTests starts Tomcat listening on 8080.
Comment From: wilkinsona
@SpringBootTest(webEnvironment = WebEnvironment.NONE) isn't broken in general. The profile smoke test has an application.properties file in src/test/resources (introduced in https://github.com/spring-projects/spring-boot/commit/eb6b48fff03e5bce063a88a10ad4ec2b8c9510a9) that sets spring.main.web-application-type=reactive. This results in the SpringApplication's web application type being set to NONE and then being set to REACTIVE. That feels the wrong way around to me. I think that what is configured by @SpringBootTest should win if it's setting it to NONE.
Comment From: philwebb
I think #29169 was a regression so we aligned things with the prior behavior. We should double check what used to happen if you had a property and a webEnvironment attribute set.
Comment From: wilkinsona
Thanks, Phil. It looks like it has always behaved this way. I've tried various 2.5.x releases and, with spring.main.web-application-type set to reactive (or servlet), we consistently start the web server even when the test sets the web environment to none.
spring.main.web-application-type is being treated as an override for webEnvironment on @SpringBootTest and I don't think that's quite right as there isn't a perfect mapping between the two. If webEnvironment is set to DEFINED_PORT, MOCK, or RANDOM_PORT, it needs to be used in combination with spring.main.web.application-type to ensure that the right kind of web environment is created. If webEnvironment is set to NONE, I think spring.main.web-application-type should be overridden with a value of none.
Comment From: wilkinsona
We should be able to revert https://github.com/spring-projects/spring-boot/commit/a3cdc4e79981a911361c284f73f9074008d5a049 as part of fixing this.
Comment From: wilkinsona
I have a fix for this that I think is suitable for 2.5.x. The problem's also quite closely related to https://github.com/spring-projects/spring-boot/issues/29170 so I think it's worth fixing in maintenance releases.
Comment From: midovlvn
@wilkinsona please take a look on my question https://stackoverflow.com/questions/71312147/is-it-possible-to-modify-springboottest-webenvironment-at-runtime
My need is "reverted" than PR - I would like to change webEnvironment = NONE/RANDOM_PORT by property