Skip to main content
added 2 characters in body
Source Link
Javasick
  • 3.1k
  • 1
  • 26
  • 36

Using Spring Boot 1.5.16 in WebMvcTest I'm trying to load test.properties applying @TestPropertySource annotation in order to override some properties in test class. This works just fine if I put it on test class:

@RunWith(SpringRunner.class) @WebMvcTest @TestPropertySource("classpath:test.properties") public class ControllerTest { ... } 

But properties not loaded if I move it to imported configuration:

@RunWith(SpringRunner.class) @WebMvcTest @Import(ControllersConfiguration.class) public class ControllerTest { ... } 

and ControllersConfigurationControllersConfiguration class is:

@TestConfiguration @TestPropertySource("classpath:test.properties") public class ControllersConfiguration { ... } 

Can you explain that behavior?

P.S. @PropertySource annotation is working in imported configuration, but with lowest precedence than application.properties

UPD: To be clear - try to make all test pass here: https://github.com/Javasick/WeirdTestPropertySource

Using Spring Boot 1.5.16 in WebMvcTest I'm trying to load test.properties applying @TestPropertySource annotation in order to override some properties in test class. This works just fine if I put it on test class:

@RunWith(SpringRunner.class) @WebMvcTest @TestPropertySource("classpath:test.properties") public class ControllerTest { ... } 

But properties not loaded if I move it to imported configuration:

@RunWith(SpringRunner.class) @WebMvcTest @Import(ControllersConfiguration.class) public class ControllerTest { ... } 

and ControllersConfiguration class is:

@TestConfiguration @TestPropertySource("classpath:test.properties") public class ControllersConfiguration { ... } 

Can you explain that behavior?

P.S. @PropertySource annotation is working in imported configuration, but with lowest precedence than application.properties

UPD: To be clear - try to make all test pass here: https://github.com/Javasick/WeirdTestPropertySource

Using Spring Boot 1.5.16 in WebMvcTest I'm trying to load test.properties applying @TestPropertySource annotation in order to override some properties in test class. This works just fine if I put it on test class:

@RunWith(SpringRunner.class) @WebMvcTest @TestPropertySource("classpath:test.properties") public class ControllerTest { ... } 

But properties not loaded if I move it to imported configuration:

@RunWith(SpringRunner.class) @WebMvcTest @Import(ControllersConfiguration.class) public class ControllerTest { ... } 

and ControllersConfiguration class is:

@TestConfiguration @TestPropertySource("classpath:test.properties") public class ControllersConfiguration { ... } 

Can you explain that behavior?

P.S. @PropertySource annotation is working in imported configuration, but with lowest precedence than application.properties

UPD: To be clear - try to make all test pass here: https://github.com/Javasick/WeirdTestPropertySource

added 106 characters in body
Source Link
Javasick
  • 3.1k
  • 1
  • 26
  • 36

Using Spring Boot 1.5.16 in WebMvcTest I'm trying to load test.properties applying @TestPropertySource annotation in order to override some properties in test class. This works just fine if I put it on test class:

@RunWith(SpringRunner.class) @WebMvcTest @TestPropertySource("classpath:test.properties") public class ControllerTest { ... } 

But properties not loaded if I move it to imported configuration:

@RunWith(SpringRunner.class) @WebMvcTest @Import(ControllersConfiguration.class) public class ControllerTest { ... } 

and ControllersConfiguration class is:

@TestConfiguration @TestPropertySource("classpath:test.properties") public class ControllersConfiguration { ... } 

Can you explain that behavior?

P.S. @PropertySource annotation is working in imported configuration, but with lowest precedence than application.properties

UPD: To be clear - try to make all test pass here: https://github.com/Javasick/WeirdTestPropertySource

Using Spring Boot 1.5.16 in WebMvcTest I'm trying to load test.properties applying @TestPropertySource annotation in order to override some properties in test class. This works just fine if I put it on test class:

@RunWith(SpringRunner.class) @WebMvcTest @TestPropertySource("classpath:test.properties") public class ControllerTest { ... } 

But properties not loaded if I move it to imported configuration:

@RunWith(SpringRunner.class) @WebMvcTest @Import(ControllersConfiguration.class) public class ControllerTest { ... } 

and ControllersConfiguration class is:

@TestConfiguration @TestPropertySource("classpath:test.properties") public class ControllersConfiguration { ... } 

Can you explain that behavior?

P.S. @PropertySource annotation is working in imported configuration, but with lowest precedence than application.properties

Using Spring Boot 1.5.16 in WebMvcTest I'm trying to load test.properties applying @TestPropertySource annotation in order to override some properties in test class. This works just fine if I put it on test class:

@RunWith(SpringRunner.class) @WebMvcTest @TestPropertySource("classpath:test.properties") public class ControllerTest { ... } 

But properties not loaded if I move it to imported configuration:

@RunWith(SpringRunner.class) @WebMvcTest @Import(ControllersConfiguration.class) public class ControllerTest { ... } 

and ControllersConfiguration class is:

@TestConfiguration @TestPropertySource("classpath:test.properties") public class ControllersConfiguration { ... } 

Can you explain that behavior?

P.S. @PropertySource annotation is working in imported configuration, but with lowest precedence than application.properties

UPD: To be clear - try to make all test pass here: https://github.com/Javasick/WeirdTestPropertySource

Source Link
Javasick
  • 3.1k
  • 1
  • 26
  • 36

Spring Boot: @TestPropertySource not loaded from imported configuration

Using Spring Boot 1.5.16 in WebMvcTest I'm trying to load test.properties applying @TestPropertySource annotation in order to override some properties in test class. This works just fine if I put it on test class:

@RunWith(SpringRunner.class) @WebMvcTest @TestPropertySource("classpath:test.properties") public class ControllerTest { ... } 

But properties not loaded if I move it to imported configuration:

@RunWith(SpringRunner.class) @WebMvcTest @Import(ControllersConfiguration.class) public class ControllerTest { ... } 

and ControllersConfiguration class is:

@TestConfiguration @TestPropertySource("classpath:test.properties") public class ControllersConfiguration { ... } 

Can you explain that behavior?

P.S. @PropertySource annotation is working in imported configuration, but with lowest precedence than application.properties