How to pass the -D System properties while testing on Eclipse?
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:
- Add
-Dlabel="label_value"
in the VM arguments of the testRun 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