Automatically add properties when running JUnit in Eclipse

后端 未结 5 903
猫巷女王i
猫巷女王i 2021-02-04 05:08

In order to run my unit tests on my Eclipse, I need to set some properties for the VM.

Thus, when I first run my JUnit test, I go in \"Open Run Dialog\", then in my JUni

5条回答
  •  感情败类
    2021-02-04 05:23

    I never understood why the launch configurations have a way to define environment variables but the only way of adding a system property seems to be to add vm arguments.

    The way I've worked around this is to have tests (or an abstract tests base class) test for the presence of required properties, if they aren't there then I load them from a .properties file on the classpath.

    This works as I can still override them or specify them from ANT or Maven but can also 'right click' -> Run As -> Junit Test the individual test files.

    edit: here is an example of getting Spring to optionally load a properties file in the same manner as described above:

    
            
            
            
                
            
    
    

提交回复
热议问题