title: Appropriate usage of TestPropertyValues in Spring Boot Tests
body: <p>I came across <code>TestPropertyValues</code>, which is briefly mentioned in the Spring Boot docs here: <a href="https://github.com/spring-projects/spring-boot/blob/2.1.x/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc#testpropertyvalues" rel="noreferrer">https://github.com/spring-projects/spring-boot/blob/2.1.x/spring-boot-project/spring-boot-docs/src/main/asciidoc/spring-boot-features.adoc#testpropertyvalues</a></p>
  
  <p>It's also mentioned in the Migration Guide here: <a href="https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#environmenttestutils" rel="noreferrer">https://github.com/spring-projects/spring-boot/wiki/Spring-Boot-2.0-Migration-Guide#environmenttestutils</a></p>
  
  <p>Both examples show an <code>environment</code> variable to apply the properties to, but there's no other documentation that I could find.</p>
  
  <p>In my tests the property setting comes too late to affect the property injection (via <code>@Value</code>) for a Spring Bean. In other words, I have a constructor like this:</p>
  
  <pre><code>  public PhoneNumberAuthorizer(@Value("${KNOWN_PHONE_NUMBER}") String knownRawPhoneNumber) {
      this.knownRawPhoneNumber = knownRawPhoneNumber;
    }
  </code></pre>
  
  <p>Since the above constructor is called before the test code has a chance to run, there's no way change the property via <code>TestPropertyValues</code> in the test before it's used in the constructor.</p>
  
  <p>I understand that I can use the <code>properties</code> parameter for <code>@SpringBootTest</code>, which updates the environment before beans get created, so what's the appropriate usage of <code>TestPropertyValues</code>?</p>