title: Loading test application.yml properties
body: <p>I have a test properties file under <code>src/test/resources/application.yml</code>.  But I cannot get the values to load in my unit test.  I have the following class:</p>
  
  <pre><code>@ConfigurationProperties("snmp")
  open class SnmpProperties {
  
      var port: Int = 1611
      lateinit var protocol: String
      lateinit var host: String
  
      override fun toString(): String {
          return "SnmpProperties(port=$port, protocol='$protocol', host='$host')"
      }
  }
  </code></pre>
  
  <p>which in the production code, loads in the values from <code>/src/main/resources/application.yml</code>.</p>
  
  <pre><code>snmp:
    port: 1161
    protocol: udp
    host: 0.0.0.0
  </code></pre>
  
  <p>Unit test class:</p>
  
  <pre><code>@CamelSpringBootTest
  @SpringBootApplication
  @EnableAutoConfiguration
  open class SnmpRouteTest : CamelTestSupport() {
  
      @Autowired
      lateinit var snmpProperties: SnmpProperties
  
      @Mock
      lateinit var repository: IPduEventRepository
  
      @InjectMocks
      lateinit var snmpTrapRoute: SnmpTrapRoute
  
      @Before
      fun setup() {
          initMocks(this)
      }
  </code></pre>
  
  <p>I have tried to add a <code>test</code> profile to each <code>application.yml</code> files to see if that adding <code>@ActiveProfiles("test")</code> worked, but it didn't.</p>
  
  <p><strong>src/main/resources/application.yml &amp;
  src/test/resources/application.yml</strong></p>
  
  <pre><code># Test profile
  spring:
    profiles: test
  snmp:
    port: 1161
    protocol: udp
    host: 0.0.0.0
  </code></pre>
  
  <p>I've also created a TestConfiguration class which creates the <code>SnmpProperties</code> bean and autowire it into the test class using <code>@EnableConfigurationProperties(TestConfiguration::class)</code>:</p>
  
  <pre><code>@Configuration
  @EnableConfigurationProperties(SnmpProperties::class)
  open class TestConfiguration {
  
      @Bean
      open fun snmpProperties() = SnmpProperties()
  }
  </code></pre>
  
  <p>Again, no go.  The error I get is:</p>
  
  <pre><code>Cannot instantiate @InjectMocks field named 'snmpTrapRoute' of type 'class org.meanwhile.in.hell.camel.snmp.receiver.route.SnmpRoute'.
  You haven't provided the instance at field declaration so I tried to construct the instance.
  However the constructor or the initialization block threw an exception : Parameter specified as non-null is null: method org.meanwhile.in.hell.camel.snmp.receiver.route.SnmpTrapRoute.&lt;init&gt;, parameter snmpProperties
  </code></pre>