- 
                Notifications
    You must be signed in to change notification settings 
- Fork 38.8k
Description
I find the inheritance behaviour of @ActiveProfiles to be a bit confusing. According to the documentation the inheritProfiles property allows to define "Whether bean definition profiles from superclasses and enclosing classes should be inherited.".
Technically, this is indeed the behaviour. If I create this meta-annotation:
@Target({ElementType.TYPE})
@Retention(RetentionPolicy.RUNTIME)
@SpringBootTest
@ActiveProfiles("integration-test")
public @interface MyAppSpringBootTest {
}and I have this base class:
@MyAppSpringBootTest
public abstract class AbstractTestClass {
}Then, I can write this test and it works:
@ActiveProfiles("extra-profile")
public class ExampleTestUsingClass extends AbstractTestClass {
  @Autowired
  private Environment environment;
  @Test
  void test() {
    assertThat(environment.getActiveProfiles())
        .containsExactlyInAnyOrder("integration-test", "extra-profile");
  }
}What surprised me was that it does not work with an interface. So if I have this interface:
@MyAppSpringBootTest
public interface AbstractTestInterface {
}Then this test will fail:
@ActiveProfiles("extra-profile")
public class ExampleTestUsingInterface implements AbstractTestInterface {
  @Autowired
  private Environment environment;
  @Test
  void test() {
    assertThat(environment.getActiveProfiles())
        .containsExactlyInAnyOrder("integration-test", "extra-profile");
  }
}Only extra-profile is active.
What also fails is this:
@MyAppSpringBootTest
@ActiveProfiles("extra-profile")
public class ExampleTest {
  @Autowired
  private Environment environment;
  @Test
  void test() {
    assertThat(environment.getActiveProfiles())
        .containsExactlyInAnyOrder("integration-test", "extra-profile");
  }
}This last example is what I actually want to use, I like to avoid base classes or interfaces for my test. Just using meta-annotations feels the "cleanest" to me.
Would it be possible to align this behaviour?