Introduce annotation to skip test based on active Spring profile [SPR-11677]
See original GitHub issueTorsten Krah opened SPR-11677 and commented
I’ve looked at the @IfProfileValue
and @ActiveProfiles
annotations, but neither does what I am searching for.
We are using the "spring.profiles.active"
system property to activate different profiles, even at the test level – e.g. "h2, default"
or something else.
We have tests which are only for Oracle and should therefore only be run if the "oracle"
profile is active, but I’ve found no way to express this on the test class itself.
A dedicated annotation would be nice to support this.
Affects: 4.0.3
Issue Links:
- #12410 Decide what to do with
@IfProfileValue
- #9538 Introduce strategy for determining if a profile value is enabled for a particular test environment
- #13622 Allow overriding
@ActiveProfiles
in test classes with system property - #13625 SystemProfileValueSource is not very compatible with the new 3.1 default system property profiles
8 votes, 8 watchers
Issue Analytics
- State:
- Created 9 years ago
- Comments:5
Top Results From Across the Web
how to run/turn off selective tests based on profiles in spring boot
You would want to use the @IfProfileValue annotation. Unfortunately it doesn't work directly on the active profiles but it can read a property...
Read more >Setting Default Spring Profile for Tests with Override Option
So we decided to have all Spring tests running with test profile. Setting test profile. There are few ways to setup active profiles...
Read more >Don't Use the @Profile Annotation in a Spring Boot App!
This configuration adds a bean of type MockService to the application context if the test profile is active, and a bean of type...
Read more >Spring Profiles - Baeldung
In this tutorial, we'll focus on introducing Profiles in Spring. ... Tests make it very easy to specify what profiles are active using...
Read more >How to use Spring Profiles - Tutorial with Examples - amitph
Examples of Spring and Spring Boot active profiles, @Profile annotation, ... Introduction to Spring Profiles – Learn Spring and Spring Boot Profiles to...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Caleb Cushing commented
Why not just allow test methods and test classes to be annotated with ```java
@Profile
Christoph Strobl commented
Hi, we’ve had similar requirements when testing against different versions. Basically we created a custom JUnit
@Rule
to disbale tests for features only available in Redis 2.8 when running against 2.6.Let me outline what I am thinking of in terms of dealing with spring profiles.
I’ve added a sample below basically adding a new annotation
IfSpringProfileActive
holding the desired profile name. TheSpringProfileRule
checks for the presence ofIfSpringProfileActive
, loads the currentEnvironment
if not already set, and verifies that the desired profile is currently active.There’s
SpringRuleTest
at the end of the sample to show what it does.