注释类型 IfProfileValue
@Target({TYPE,METHOD}) @Retention(RUNTIME) @Documented @Inherited public @interface IfProfileValue
Test annotation to indicate whether a test is enabled or disabled for a specific testing profile.In the context of this annotation, the term profile refers to a Java system property by default; however, the semantics can be changed by implementing a custom
ProfileValueSource. If the configuredProfileValueSourcereturns a matchingvalue()for the declaredname(), the test will be enabled. Otherwise, the test will be disabled and effectively ignored.@IfProfileValuecan be applied at the class level, the method level, or both. Class-level usage of@IfProfileValuetakes precedence over method-level usage for any methods within that class or its subclasses. Specifically, a test is enabled if it is enabled both at the class level and at the method level; the absence of@IfProfileValuemeans the test is implicitly enabled. This is analogous to the semantics of JUnit's@Ignoreannotation, except that the presence of@Ignorealways disables a test.Example
When usingSystemProfileValueSourceas theProfileValueSourceimplementation (which is configured by default), you can configure a test method to run only on Java VMs from Oracle as follows:@IfProfileValue(name = "java.vendor", value = "Oracle Corporation") public void testSomething() { // ... }'OR' Semantics
You can alternatively configure
@IfProfileValuewith OR semantics for multiplevalues(). The following test will be enabled if aProfileValueSourcehas been appropriately configured for the"test-groups"profile with a value of eitherunit-testsorintegration-tests. This functionality is similar to TestNG's support for test groups and JUnit's experimental support for test categories.@IfProfileValue(name = "test-groups", values = { "unit-tests", "integration-tests" }) public void testWhichRunsForUnitOrIntegrationTestGroups() { // ... }@IfProfileValuevs.@ProfileAlthough the
@IfProfileValueand@Profileannotations both involve profiles, they are not directly related.@Profileinvolves bean definition profiles configured in theEnvironment; whereas,@IfProfileValueis used to enable or disable tests.Meta-annotation Support
As of Spring Framework 4.0, this annotation may be used as a meta-annotation to create custom composed annotations.
- 从以下版本开始:
- 2.0
- 作者:
- Rod Johnson, Sam Brannen
- 另请参阅:
ProfileValueSource,SystemProfileValueSource,ProfileValueSourceConfiguration,ProfileValueUtils,AbstractJUnit4SpringContextTests,SpringJUnit4ClassRunner,ProfileValueChecker,Profile,ActiveProfiles