title: Configuration properties are not loaded in Spring Test
body: <p>I have a Spring Boot application which has some configuration properties. I'm trying to write a test for some of the components and want to load configuration properties from a <code>test.properties</code> file. I can't get it to work.</p>
  
  <p>Here's my code:</p>
  
  <p><code>test.properties</code> file (under src/test/resources):</p>
  
  <pre><code>vehicleSequence.propagationTreeMaxSize=10000
  </code></pre>
  
  <p>Configuration properties class:</p>
  
  <pre><code>package com.acme.foo.vehiclesequence.config;
  
  import javax.validation.constraints.NotNull;
  
  import org.springframework.boot.context.properties.ConfigurationProperties;
  import org.springframework.stereotype.Component;
  
  @Component
  @ConfigurationProperties(prefix = VehicleSequenceConfigurationProperties.PREFIX)
  public class VehicleSequenceConfigurationProperties {
      static final String PREFIX = "vehicleSequence";
  
      @NotNull
      private Integer propagationTreeMaxSize;
  
      public Integer getPropagationTreeMaxSize() {
          return propagationTreeMaxSize;
      }
  
      public void setPropagationTreeMaxSize(Integer propagationTreeMaxSize) {
          this.propagationTreeMaxSize = propagationTreeMaxSize;
      }
  }
  </code></pre>
  
  <p>My test:</p>
  
  <pre><code>@RunWith(SpringRunner.class)
  @ContextConfiguration(classes = VehicleSequenceConfigurationProperties.class)
  @TestPropertySource("/test.properties")
  public class VehicleSequenceConfigurationPropertiesTest {
  
      @Autowired
      private VehicleSequenceConfigurationProperties vehicleSequenceConfigurationProperties;
  
      @Test
      public void checkPropagationTreeMaxSize() {
          assertThat(vehicleSequenceConfigurationProperties.getPropagationTreeMaxSize()).isEqualTo(10000);
      }
  }
  </code></pre>
  
  <p>The test fails with "Expecting actual not to be null" meaning the property <code>propagationTreeMaxSize</code> in the configuration properties class was not set.</p>