Issue 1:
Dave Syer opened SPR-7731 and commented

Overview

Sometimes (always?) it would be nice to have a @Rule implementation that did the job of the SpringJUnit4ClassRunner.

The main motivation for this is to be able to use other runners (e.g. @Parameterized, @Categories, Mockito, etc.).

There might even be a case for deprecating the runner in favor of a @Rule?

Further Resources

junit-team/junit4#200

junit-team/junit4#444

junit-team/junit4#766

#222

https://github.com/mmichaelis/spring-aware-rule

Attachments:

SpringContextRule.java (4.72 kB)

SpringContextRule.java (4.49 kB)

spring-test-4.2.0.BUILD-SNAPSHOT.jar (501.52 kB)

Issue Links:

#11259 Introduce a TestExecutionListener for DbUnit ("Cloned from")

#17629 Document SpringClassRule and SpringMethodRule in the reference manual ("is depended on by")

#13870 JUnit @Rule executes outside of transaction when using the TransactionalTestExecutionListener ("is depended on by")

#14850 Implement JUnit 4 Support using Rules ("is duplicated by")

#9965 Add support for parameterized JUnit 4 tests in the Spring TestContext Framework

25 votes, 30 watchers

Issue 2:
Matthew T. Adams opened SPR-9281 and commented

I've found a case where the ability to specify that certain bean profiles are active by default is extremely convenient.

We are migrating from one environment to another (from pure Hibernate to JPA) in an evolutionary fashion. When not specifying any active bean profiles, the legacy environment is intended for backward compatibility reasons; when the new environment is desired, only then would the user wish to set the system property "spring.profiles.active" and specify that he wanted to use the "new stuff" (JPA in this case).

As an alternative to #12852, the choice could be explicitly made by the author of the application context by adding an attribute called "default-profile-activation" similar to the <beans> element. This would serve to remove any magic.

If "default-profile-activation" were an enumerated value, it would make the behavior explicit. Values I'd recommend are the following.

"inactive-by-default": The profile being described is inactive by default and activated only explicitly. This is the default value if a "profile" attribute is given. It could be a warning if this value is provided and a nonempty "profile" attribute value were given.

"active-unless-specified": The profile being described is active by default, unless other means of explicit activation are provided, like via the "spring.profiles.active" system property.

"active-always": The profile being described is always active, regardless of explicit profile activations. This value is intended for backward compatibility with the <beans> element when it has an empty or no "profile" attribute. It could be a warning if users provided both a "profile" attribute and a "default-profile-activation" value of "active-always".

Consider the following file.

<beans> <!-- no 'profile' attribute, 'default-profile-activation' value is 'active-always' -->

<bean id="a" class="com.acme.A"/>

</beans>

<beans profile="jpa"> <!-- 'default-profile-activation' value is 'inactive-by-default' -->

<bean id="b" class="com.acme.B"/>

</beans>

<beans profile="pure-hibernate" default-profile-activation="active-unless-specified">

<bean id="c" class="com.acme.C"/>

</beans>

<beans default-profile-activation="active-always"> <!-- no 'profile' attribute, results in warning since this is the default in this case? -->

<bean id="d" class="com.acme.D"/>

</beans>

<beans profile="jpa" default-profile-activation="inactive-by-default"> <!-- 'profile' attribute given, results in warning since this is the default in this case? -->

<bean id="e" class="com.acme.E"/>

</beans>

If the profile "pure-hibernate" or no profiles were explicitly activated, then the beans defined would be [a, c, d].

If the profile "jpa" were activated, then the beans defined would be [a, b, d, e].

If the profile "foobar", which is not mentioned in the example, were activated, then the beans defined would be [a, d].

Affects: 3.1.1

Issue Links:

#15881 Add explanation of @Profile("default") to reference documentation ("is depended on by")

#12852 Introduce a reserved default profile name ("duplicates")