title: Spring Boot test with yaml properties by profile
body: <p>So there's a lot of hits on this topic, but none of them have worked for me.</p>
  
  <p>I have a very simple configuration class:</p>
  
  <pre><code>@Configuration
  @ConfigurationProperties(prefix = "props")
  public class TagIncluder {
  
      private static final String PARAMETER_NAME = "tags";
  
      private List&lt;String&gt; tags;
  
      public TagIncluder() {
          tags = new ArrayList&lt;&gt;();
      }
  
      public List&lt;String&gt; getTags() {
          return tags;
      }
  
      @Handler
      public void attachIncludedTags(Exchange exchange) {
          exchange.getIn().setHeader(PARAMETER_NAME, tags);
      }
  }
  </code></pre>
  
  <p>I want this class to be able to load different property files. I am using yaml, and my file is named <code>application-tag_test.yml</code>. I have tried placing this file in <code>src/main/resources</code>, <code>src/test/resources</code> and <code>src/test/resources/config</code>, but it is never picked up.</p>
  
  <p>This is the contents of the property file:</p>
  
  <pre><code>props:
    tags:
      - test 
  </code></pre>
  
  <p>And finally, the test case:</p>
  
  <pre><code>@SpringBootTest
  @ActiveProfiles("tag_test")
  @RunWith(SpringJUnit4ClassRunner.class)
  @ContextConfiguration(classes = TagIncluder.class)
  public class TagIncluderTest extends ExchangeTestSupport {
  
      @Autowired
      private TagIncluder sut;
  
      @Test
      public void attachIncludedTags_shouldUseTagsInFileIfFileSpecified() {
          Exchange testExchange = createExchange();
          sut.attachIncludedTags(testExchange);
  
          Assertions.assertThat(testExchange.getIn().getHeader("tags", List.class))
              .size().isGreaterThanOrEqualTo(1);
      }
  }
  </code></pre>
  
  <p>Additionally, I have tried placing an <code>application.properties</code> file in the above described locations with the following content:</p>
  
  <pre><code>spring.profiles.active=tag_test
  </code></pre>
  
  <p>What is required for Spring to set my yaml file as the desired configuration for my test class under test?</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>So after some exploration and trial and error, I have found that the following works:</p>
  
  <pre><code>@SpringBootTest
  @ActiveProfiles("tag_test")
  @RunWith(SpringJUnit4ClassRunner.class)
  public class TagIncluderTest extends ExchangeTestSupport {
  
      @Autowired
      private TagIncluder sut;
  
      @Test
      public void attachIncludedTags_shouldUseTagsInFileIfFileSpecified() {
          Exchange testExchange = createExchange();
          sut.attachIncludedTags(testExchange);
  
          Assertions.assertThat(testExchange.getIn().getHeader("tags", List.class))
              .size().isGreaterThanOrEqualTo(1);
      }
  }
  </code></pre>
  
  <p>The difference here is that I've removed the <code>@ContextConfiguration</code> annotation and I let Spring take care of all of that. </p>
  
  <p>It is a lot slower, and I would prefer specifying what is needed. I think this might break in the future, for instance if I add another configuration class that will start with the entire context and throw errors because those properties are not included in my <code>application-tag_test.yml</code> configuration.</p>
  
  <p>Finally, any of the above locations I tried for the configuration is valid with the above annotations. The <code>application.properties</code> to specify a profile is not needed.</p>
  
  <p>If anyone knows a way to specify <strong>what</strong> should be loaded into the context instead, I'd be very grateful for another solution.</p>