1

I know I can use @TestPropertySource. But annotations accept only literals. what if i want to compute the values or even if i want to compute which properties i want to override. is it doable in spring? how can i register arbitrary properties in spring's Environment in tests?

Michael Petch
  • 46,082
  • 8
  • 107
  • 198
piotrek
  • 13,982
  • 13
  • 79
  • 165

1 Answers1

0

You can use spring profiles to load up a configuration object. By encapsulating the configuration you can compute the values to use in test profile.

Stefa
  • 656
  • 5
  • 13
  • i know how to use profiles but how can i load/build a configuration object that compute property names and values? – piotrek Jul 10 '17 at 20:12
  • Can you give me a use case? – Stefa Jul 10 '17 at 20:16
  • i want to read user's local config (ignored by git) that tells on which port user has local database. and then use that port to configure datasource in spring tests – piotrek Jul 10 '17 at 23:50
  • This sounds exactly the problem profiles solve. Whenever I had a local environment that differs from the other environments, I commit a local profile, then add it to git ignore. That way everyone picks it up and can modify it without impacting others. – Stefa Jul 12 '17 at 20:33