The unit test class defined in src/test/... starts with:
@SpringBootTest
@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes={MyProperties.class})
public class ConnectionTest {
@Autowired
MyProperties props;
// ...
The MyProperties.class is defined in src/main/...:
@ConfigurationProperties(prefix = "app")
public final class MyProperties {
@NotEmpty private String name;
// ...
When the MyProperties is injected in src/main/... then the values which it has are taken from src/resources/application.properties file.
But when the MyProperties is injected in src/test/... as I shown above then the values are null.