Versions
Version of Spring Boot: 4.0.0, after migration from 3.5.x
Context
I have a JUnit test class annotated with @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT). This class does not contain any tests itself. Instead, it inherits from an abstract class that implements test methods within an inner classes annotated with JUnit's @Nested. In the abstract parent class, I want to inject the value of the web server's port using @LocalServerPort on a local field.
Observed
A NumberFormatException occurs when I try to retrieve the port value as an int. When I retrieve it as a String, I obtain "${local.server.port}". This behavior only occurs when I use both class inheritance and a nested test class in the parent class. With nested test classes directly inside the @SpringBootTest class, the port value is OK. With test methods in an abstract parent class but without a nested class, the port value is OK. The configuration with both inheritance and nested test classes works with Spring Boot 3.5.
Expected
Have the port value correctly injected in the configuration with inheritance and nested test class.
Attachments
Simplified project to reproduce the issue:
issue-spring-boot-4.zip
Versions
Version of Spring Boot: 4.0.0, after migration from 3.5.x
Context
I have a JUnit test class annotated with
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT). This class does not contain any tests itself. Instead, it inherits from an abstract class that implements test methods within an inner classes annotated with JUnit's@Nested. In the abstract parent class, I want to inject the value of the web server's port using@LocalServerPorton a local field.Observed
A
NumberFormatExceptionoccurs when I try to retrieve the port value as anint. When I retrieve it as aString, I obtain"${local.server.port}". This behavior only occurs when I use both class inheritance and a nested test class in the parent class. With nested test classes directly inside the@SpringBootTestclass, the port value is OK. With test methods in an abstract parent class but without a nested class, the port value is OK. The configuration with both inheritance and nested test classes works with Spring Boot 3.5.Expected
Have the port value correctly injected in the configuration with inheritance and nested test class.
Attachments
Simplified project to reproduce the issue:
issue-spring-boot-4.zip