Skip to content

Rework slides, task, and solution of "Test your profiles" #70

@rweisleder

Description

@rweisleder

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    taskAnything related to course taskstestingAnything test-related

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions