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?
            Asked
            
        
        
            Active
            
        
            Viewed 273 times
        
    1
            
            
         
    
    
        Michael Petch
        
- 46,082
- 8
- 107
- 198
 
    
    
        piotrek
        
- 13,982
- 13
- 79
- 165
- 
                    Not sure, but are you looking for `PropertySourcesPlaceholderConfigurer`? – Rana_S Jul 10 '17 at 18:23
- 
                    What about `System.setProperty("myproperty", "foo");` ? https://stackoverflow.com/a/12144312/1199132 – Aritz Jul 10 '17 at 20:09
1 Answers
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
- 
                    
- 
                    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