The slides and task hints for "Test your profiles" suggest to use @EnabledIf to test the configuration depending on the active profiles. With this approach, we would have to run the test once with the affected profile activated and once without the affected profile activated, either manually or via the build system.
From my point of view @EnabledIf should be used for conditions we have no influence on in our tests, for example the used operating system.
For this specific task and in day-to-day projects, I would be using @ActiveProfiles instead and testing the different cases that way. In my last workshop I came up with this sample solution:
@SpringBootTest
class ApplicationPropertiesTest {
@Nested
@ActiveProfiles("prod")
class InProduction {
@Value("${server.port}")
private int port;
@Test
void port_should_be_8090() {
assertThat(port).isEqualTo(8090);
}
}
@Nested
class DuringDevelopment {
@Value("${server.port:8080}")
private int port;
@Test
void port_should_be_8080() {
assertThat(port).isEqualTo(8080);
}
}
}
Regarding the slides, I suggest to delete the slide with @EnabledIf and move the slide containing @ActiveProfiles to that position.
The slides and task hints for "Test your profiles" suggest to use
@EnabledIfto test the configuration depending on the active profiles. With this approach, we would have to run the test once with the affected profile activated and once without the affected profile activated, either manually or via the build system.From my point of view
@EnabledIfshould be used for conditions we have no influence on in our tests, for example the used operating system.For this specific task and in day-to-day projects, I would be using
@ActiveProfilesinstead and testing the different cases that way. In my last workshop I came up with this sample solution:Regarding the slides, I suggest to delete the slide with
@EnabledIfand move the slide containing@ActiveProfilesto that position.