5

I have a @SpringBootTest which is used to execute an integration test on the server. Depending on the configuration I want the server to behave differently. The configuration itself is read by beans (scope = singleton) deep inside my app logic and they read the property via @Value annotation.

How could I execute the same test with different configuration settings? I have tried to write different test classes and annotate them with @TestPropertySource(properties = XYZ). But it seems that this affects all other tests as well (due to the singleton scope?). It there a way to reset the properties after the test?

To respecify my problem: I want to configure my bean with a different @Value property during my tests and this value should only be valid throughout this specific test execution.

Thanks ahead for any pointers.

Misagh Moayyed
  • 4,154
  • 2
  • 15
  • 25
smigfu
  • 855
  • 1
  • 6
  • 9

1 Answers1

2

I have a webservice, which is connecting to the client of other webservice by using property from the config. As in any organization, we have different environments. For testing, I wanted to hit testing env instead of local. This is how I override the default property value only for integration test. By doing this, I can hit the test env instead of default local env.

@SpringBootTest(value = {"eureka.client.enabled=false", // Don't start Eureka
"com.somepackage.webservicename.client.serviceUrl = http://nodename.envname:26730"})

Hope this helps!

mufeez-shaikh
  • 179
  • 2
  • 14