When using useMainMethod = SpringBootTest.UseMainMethod.NEVER, properties are passed into the Environment, so this test passes:
@SpringBootTest(properties = "test=1", useMainMethod = SpringBootTest.UseMainMethod.NEVER)
class UseMainMethodsApplicationTests {
@Test
void contextLoads(@Autowired Environment environment) {
assertThat(environment.getProperty("test")).isEqualTo("1");
}
}
When setting useMainMethod = SpringBootTest.UseMainMethod.WHEN_AVAILABLE or useMainMethod = SpringBootTest.UseMainMethod.ALWAYS, the properties passed via properties attribute are not in the environment. This test fails:
@SpringBootTest(properties = "test=1", useMainMethod = SpringBootTest.UseMainMethod.ALWAYS)
class UseMainMethodsApplicationTests {
@Test
void contextLoads(@Autowired Environment environment) {
assertThat(environment.getProperty("test")).isEqualTo("1");
}
}
expected: "1"
but was: null
If this is intended, we should add a note to the docs.
Observed in Spring Boot 3.0.0 RC1.