We have multiple test classes in our spring boot application. Some of the classes contain integration tests, some contain unit tests. These means that if I (e.g. with maven) let all tests to be executed, it will run all tests in all classes.
What I like to achieve is that the integration tests are executed only, if a specific spring profile is set, e.g. via application.yml. I like e.g. to annotate the whole test class to define that the tests in this class are only executed if the specified spring profile is set. If it is not set, these tests shall be ignored.
- The topic How can I use @IfProfileValue to test if a Profile is active? goes in exactly this direction.
@IfProfileValue
looks at first glance exactly like it is what I need. But as it is pointed out, it is not. I could use it, if I would set a specific system property. But I need to use a real spring profile (and not the system propertyspring.profiles.active
- this would ignore a profile set viaapplication.yml
) @Profile
seems to look also to be what I need but as the topic Use @Profile to decide to execute test class shows, we should not use it.
So what can be done to achieve this? Note that there are a lot of questions about tests and spring profiles on stack overflow. But most of them point out how to set configurations in tests specific to spring profiles. That is not would I am looking for. I would like to execute or ignore the tests.