Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
rweisleder opened this issue Jul 22, 2023 · 1 comment
Open

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

rweisleder opened this issue Jul 22, 2023 · 1 comment
Labels
task Anything related to course tasks testing Anything test-related

Comments

@rweisleder
Copy link

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.

@BjoernKW BjoernKW added testing Anything test-related task Anything related to course tasks labels Aug 8, 2023
@BjoernKW
Copy link
Collaborator

BjoernKW commented Aug 8, 2023

I agree that @ActiveProfiles generally is the better solution for this particular use case. The goal here is to show how @EnabledIf works, though.

Can you maybe suggest a better condition to check for other than the active profile? Testing for the operating system probably doesn't make much sense in terms of this task either, because the attendees will only be running the tests on their own machines.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
task Anything related to course tasks testing Anything test-related
Projects
None yet
Development

No branches or pull requests

2 participants