I am developing on Eclipse on Windows and Code gets deployed on Unix. I am fetching the system property values using System.getProperty("key") ... How do I pass this in Eclipse so that I do not have to modify the code and it works on Eclipse for debugging?
Any suggestions?
Do you want to overwrite a system property? You can do this. final String propertyName = "Property"; String oldProperty = System. getProperty(propertyName); System.
If your test relies on system properties you could set them and unset them in 'before' and 'after' lifecycle methods. In Junit5, setting system properties for all tests in a test case might look like this: @BeforeAll public static void setSystemProperties() { // set the system properties // ... }
Programmatically, a system property can be set using the setProperty method of the System object, and also via the setProperty method of the Properties object that can be obtained from System via getProperties.
Run -> Run configurations, select project, second tab: “Arguments”. Top box is for your program, bottom box is for VM arguments, e.g. -Dkey=value
.
You can use java System.properties
, for using them from eclipse you could:
-Dlabel="label_value"
in the VM arguments of the test Run Configuration
like this:Then run the test:
import org.junit.Test; import static org.junit.Assert.assertEquals; public class Main { @Test public void test(){ System.out.println(System.getProperty("label")); assertEquals("label_value", System.getProperty("label")); } }
Finally it should pass the test and output this in the console:
label_value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With