How to pass input from command line to junit maven test program

前端 未结 3 809
伪装坚强ぢ
伪装坚强ぢ 2020-12-24 11:56

I wrote a junit test to add two numbers. I need to pass this numbers from command line. I am running this junit test from maven tool as

mvn -Dtest=AddNumbers         


        
3条回答
  •  囚心锁ツ
    2020-12-24 12:42

    Passing the numbers as system properties like suggested by @artbristol is a good idea, but I found that it is not always guaranteed that these properties will be propagated to the test.

    To be sure to pass the system properties to the test use the maven surefire plugin argLine parameter, like

    mvn -Dtest=AddNumbers -DargLine="-Dnum1=1 -Dnum2=2"
    

提交回复
热议问题