Repository navigation
Description
Dave Syer opened SPR-7754 and commented
Now that @Profile (and "profile" generally) has a meaning in the framework, the old test support for detecting system properties looks like it has an awkward name. In Spring 3.1 terms, what @IfProfileValue does is detect key-value pairs in the Environment (not profiles).
One simple thing we should definitely do is add a ProfileValueSource that can pull values from the Environment.
More radically, maybe we could rename @IfProfileValue(name=,value=) to @Environment(key=,value=).
Another suggestion is that we could provide a way to activate profiles declaratively for tests or test classes. Something I've been playing with is this (new components ProfileSuite and @ActiveProfile):
@RunWith(Suite.class)
@SuiteClasses({ HsqlTest.class, DerbyTest.class })
public class JdbcDaoIntegrationTests {
@RunWith(ProfileSuite.class)
@SuiteClasses({ JdbcSearchableJobInstanceDaoTests.class, JdbcSearchableJobExecutionDaoTests.class,
JdbcSearchableStepExecutionDaoTests.class })
public static abstract class BaseTest {
}
@ActiveProfile("hsql")
public static class HsqlTest extends BaseTest {
}
@ActiveProfile("derby")
public static class DerbyTest extends BaseTest {
}
}It says: run these three test classes twice each, once with profile "hsql" and once with profile "derby". This has the nice feature that @EnvironmentValue can still be honoured inside the individual tests (per method).
Issue Links:
SystemProfileValueSourceis not very compatible with the new 3.1 default system property profiles [SPR-8985] #13625 SystemProfileValueSource is not very compatible with the new 3.1 default system property profiles- TestContext framework should support declarative configuration of bean definition profiles [SPR-7960] #12615 TestContext framework should support declarative configuration of bean definition profiles
- Allow overriding
@ActiveProfilesin test classes with system property [SPR-8982] #13622 Allow overriding@ActiveProfilesin test classes with system property - Introduce annotation to disable test based on active Spring profile [SPR-11677] #16300 Introduce annotation to skip test based on active Spring profile
6 votes, 7 watchers
Activity
spring-projects-issues commentedon Nov 18, 2010
Chris Beams commented
Assigning to Sam for comments (and possibly implementation of course).
Sam, if you haven't gotten familiar with the Environment/Profiles support, this is probably a great time to do so.
Dave, with regard to the
@Environmentannotation, it might be more accurate to think of@Propertyor@EnvironmentPropertyor something to that effect. What's really being evaluated in this situation is properties as accessed through the environment.It should be noted that
@Profileand@IfProfileValuehave pretty close semantics already. In the case of@Profile, it indicates a@Component/@Configurationclass should loaded only if the profile(s) specified in thevalueattribute are currently active. In the case of@IfProfileValue, it indicates, that a@Testmethod should be executed only if the key/value (property) is present and matching.I'm not sure how widely used
@IfProfileValueis right now. It would be nice to consider some kind of unification of semantics in any case.spring-projects-issues commentedon Nov 18, 2010
Dave Syer commented
A more radical idea would be to remove
@IfProfileValueand replace it with@Profile. This means re-thinking Environment a little so we can avoid the "special" key name ("springProfiles" is a key name in the Environment which is special because it switches on profiles). We can do that by sticking to the old@IfProfileValuestyle definition of a profile value (it has to be explicit about its key name), so you would just have Environment with key-value pairs, and none of them would have any special status.@Profile(and similar feature in XML) would need to name the key as well as the value(s), just like@IfProfileValuedoes now, and then the latter could be simply removed in favour of the former.spring-projects-issues commentedon Nov 18, 2010
Helena Edelson commented
I like the move to
@Profileidea and have been starting to play around with an environment module that in part leverages the Sigar jar to detect environment data, explicitly filtered via Spring.spring-projects-issues commentedon Nov 30, 2010
Dave Syer commented
Another suggestion: an environment matcher utility so that you can use imperative instead of declarative approach to skipping tests by profile. E.g. somethng like this
I guess TestEnvironmentUtils would need to access the ApplicationContext and extract the environment (so maybe it would have to be a field in the test case). With this approach a user has access to all the profile and property information (name=value pairs) in the Environment.
The inverse
spring-projects-issues commentedon Dec 16, 2010
spring-projects-issues commentedon Dec 17, 2010
spring-projects-issues commentedon Oct 11, 2015
Caleb Cushing commented
deprecate the original annotation. I would like something either based on PropertySourceMerger which I believe can merge properties, the environment etc, and/or support SpEL for disabling tests. As it stands I've realized that
@IfProfileValueisn't actually valuable to me.[-]Decide what to do with @IfProfileValue [SPR-7754][/-][+]Decide what to do with `@IfProfileValue` [SPR-7754][/+]sbrannen commentedon Jan 8, 2024
Since
@IfProfileValueis specific to our JUnit 4 support and since JUnit 4 does not provide an extension mechanism for enabling/disabling tests, we have decided to leave the@IfProfileValuein place as-is as long as we continue to support JUnit 4.Regarding other topics discussed in this issue, many of the requested features and/or proposals are already possible with JUnit Jupiter (in JUnit 5) and Spring's support for JUnit Jupiter.
@DisabledIfSystemProperty,@EnabledIfEnvironmentVariable, etc.ExecutionCondition.@EnabledIfand@DisabledIfannotations that are based on SpEL expressions -- which can optionally access beans and theEnvironmentin theApplicationContext.In light of the above, I am closing this issue.