Skip to content

Decide what to do with @IfProfileValue [SPR-7754] #12410

Closed as not planned
Closed as not planned

Description

@spring-projects-issues

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:

6 votes, 7 watchers

Activity

  1. spring-projects-issues commented on Nov 18, 2010

    @spring-projects-issues
    CollaboratorAuthor

    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 @Environment annotation, it might be more accurate to think of @Property or @EnvironmentProperty or something to that effect. What's really being evaluated in this situation is properties as accessed through the environment.

    It should be noted that @Profile and @IfProfileValue have pretty close semantics already. In the case of @Profile, it indicates a @Component/@Configuration class should loaded only if the profile(s) specified in the value attribute are currently active. In the case of @IfProfileValue, it indicates, that a @Test method should be executed only if the key/value (property) is present and matching.

    I'm not sure how widely used @IfProfileValue is right now. It would be nice to consider some kind of unification of semantics in any case.

  2. spring-projects-issues commented on Nov 18, 2010

    @spring-projects-issues
    CollaboratorAuthor

    Dave Syer commented

    A more radical idea would be to remove @IfProfileValue and 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 @IfProfileValue style 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 @IfProfileValue does now, and then the latter could be simply removed in favour of the former.

  3. spring-projects-issues commented on Nov 18, 2010

    @spring-projects-issues
    CollaboratorAuthor

    Helena Edelson commented

    I like the move to @Profile idea 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.

  4. spring-projects-issues commented on Nov 30, 2010

    @spring-projects-issues
    CollaboratorAuthor

    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

    @Test
    public void shouldOnlyWorkWithOracle() {
    	assumeTrue(TestEnvironmentUtils.activeProfiles().contains("oracle"));
    	...
    }
    

    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

  5. spring-projects-issues commented on Dec 16, 2010

    @spring-projects-issues
    Author
  6. spring-projects-issues commented on Dec 17, 2010

    @spring-projects-issues
    Author
  7. spring-projects-issues commented on Oct 11, 2015

    @spring-projects-issues
    CollaboratorAuthor

    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 @IfProfileValue isn't actually valuable to me.

  8. self-assigned this
    on Jan 15, 2019
  9. added
    in: test
    type: enhancement
    on Jan 15, 2019
  10. changed the title [-]Decide what to do with @IfProfileValue [SPR-7754][/-] [+]Decide what to do with `@IfProfileValue` [SPR-7754][/+] on Jan 8, 2024
  11. removed this from the General Backlog milestone on Jan 8, 2024
  12. added
    status: declined
    on Jan 8, 2024
  13. sbrannen commented on Jan 8, 2024

    @sbrannen
    Member

    Since @IfProfileValue is 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 @IfProfileValue in 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.

    • JUnit Jupiter provides numerous built-in annotations for Conditional Test Execution such as @DisabledIfSystemProperty, @EnabledIfEnvironmentVariable, etc.
    • Users can also implement their own custom ExecutionCondition.
    • Spring provides @EnabledIf and @DisabledIf annotations that are based on SpEL expressions -- which can optionally access beans and the Environment in the ApplicationContext.

    In light of the above, I am closing this issue.

  14. removed
    type: task
    on Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: teststatus: declinedtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions