How to pass the -D System properties while testing on Eclipse?

前端 未结 6 1423
有刺的猬
有刺的猬 2020-11-29 01:52

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 Ec

相关标签:
6条回答
  • 2020-11-29 02:32

    run configuration -> arguments -> vm arguments

    (can also be placed in the debug configuration under Debug Configuration->Arguments->VM Arguments)

    0 讨论(0)
  • 2020-11-29 02:34

    Yes this is the way:

    Right click on your program, select run -> run configuration then on vm argument

    -Denv=EnvironmentName -Dcucumber.options="--tags @ifThereisAnyTag"
    

    Then you can apply and close.

    0 讨论(0)
  • 2020-11-29 02:44

    You can use java System.properties, for using them from eclipse you could:

    1. Add -Dlabel="label_value" in the VM arguments of the test Run Configuration like this:

    1. 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"));
          }
      }
      
    2. Finally it should pass the test and output this in the console:

      label_value
      
    0 讨论(0)
  • 2020-11-29 02:44

    This will work for junit. for TestNG use following command

    -ea -Dmykey="value" -Dmykey2="value2"
    
    0 讨论(0)
  • 2020-11-29 02:52

    You can add command line arguments to your run configuration. Just edit the run configuration and add -Dmyprop=value (or whatever) to the VM Arguments Box.

    0 讨论(0)
  • 2020-11-29 02:55

    Run -> Run configurations, select project, second tab: “Arguments”. Top box is for your program, bottom box is for VM arguments, e.g. -Dkey=value.

    0 讨论(0)
提交回复
热议问题