Description
Konstantin Boudnik opened SPR-5902 and commented
It seems that current implementation of @IfProfileValue
is deficient for the following reasons:
- it is possible to create a mutual-lock situation when none of a class' test methods would be executed no matter what values are set in the runtime
- current semantic contradicts an existing and documented one of
@IfProfileValue
' values, e.g. OR semantic
The code below clearly demonstrate a situation when no matter which test-group's value is set ('all', 'fast', or 'quick') none of the tests will be executed, because the class belongs to a group 'all', but its test methods are from different test groups.
It seems to be a problem in the SpringJUnit4ClassRunner semantic's implementation that a class level @IfProfileValue
actually overwrites any method's level @IfProfileValue
. Should it have same semantic as as @IfProfileValue
's 'values', i.e. with OR semantic, the problem won't exist (see the documentation at http://static.springsource.org/spring/docs/2.5.x/api/org/springframework/test/annotation/IfProfileValue.html)
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.test.annotation.IfProfileValue;
import org.springframework.test.context.TestExecutionListeners;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({})
@IfProfileValue(name = "test-group", value = "all")
public class MyTests {
@BeforeClass
public static void setUp () {
System.out.println("test-group is set to: " + System.getProperty("test-group"));
}
@Test
@IfProfileValue(name = "test-group", values = {"fast", "quick"})
public void testOne() {
System.out.println("testOne(): Quick stuff");
}
@Test
@IfProfileValue(name = "test-group", value = "fast")
public void testTwo() {
System.out.println("testTwo(): Fast stuff");
}
}
Affects: 2.5.6
Issue Links:
- Improve documentation for @IfProfileValue precedence [SPR-11902] #16521 Improve documentation for
@IfProfileValue
precedence - ProfileValueUtils#isTestEnabledInThisEnvironment should use current test class to determine IfProfileValue annotation [SPR-4526] #9203 ProfileValueUtils#isTestEnabledInThisEnvironment should use current test class to determine IfProfileValue annotation
- Annotating an integration test with @IfProfileValue at class level still loads the applications contexts even when the profile is not activated [SPR-5043] #9718 Annotating an integration test with
@IfProfileValue
at class level still loads the applications contexts even when the profile is not activated - ProfileValueUtils should enforce class-level usage of @IfProfileValue to override method-level usage [SPR-5914] #10583 ProfileValueUtils should enforce class-level usage of
@IfProfileValue
to override method-level usage - Allow multiple values be specified in the runtime for tests filtering by @IfProfileValue [SPR-5903] #10572 Allow multiple values be specified in the runtime for tests filtering by
@IfProfileValue
Referenced from: commits 2b869d5