How to pass parameter to maven test

后端 未结 3 1544
难免孤独
难免孤独 2021-01-21 01:26

I have One test suite running in two environment. Sometimes, I would like to run tests in localhost:8080 and sometimes at localhost:8585. Jenkins run the tests by \"mvn te

3条回答
  •  再見小時候
    2021-01-21 02:27

    I add a plugin on maven pom.xml

    
         org.apache.maven.plugins
         maven-surefire-plugin
         
            
              
                 fileName
                 ${fileName}
              
            
         
    
    

    And get the parameter in junit code with

    String fileName = System.getProperty("fileName");
    

    After, I run my tests with -DfileName argument

    mvn clean test -DfileName="config-test.xml"
    

    Now, I can put all configurations in xml file and load appropriate file with the corrects parameters.

    mvn clean test -DfileName="config-test.xml"
    

    or

    mvn clean test -DfileName="config-homolog.xml"
    

    I solved the problem with the tips from Sandra Sukarieh and http://syntx.io/how-to-pass-parameters-to-the-junit-tests-from-the-maven-surefire-plugin/

    Thank you very much

提交回复
热议问题