How do I pass parameters to a Junit test from Ant?

筅森魡賤 提交于 2019-12-05 18:13:28

问题


I'm using Junit under Ant to perform Selenium Test.My test cases need to read files which contain test data(in order to accomplish data driven test). I don't mind embedding the file names in the test cases, but I'd like to have the name of the directory where the data files are stored parameterized in the build.xml file.

What's the best way to pass information like that from build.xml down into the test cases? Is it a good idea to use ant property? Is it possible to inject Junit4 parameter from build.xml?


回答1:


The junit task accepts nested sysproperty elements.

<junit fork="no">
  <sysproperty key="mydatadir" value="${whatever}"/>
  ...
</junit>

You can access these from within your tests using System.getProperty().



来源:https://stackoverflow.com/questions/3777000/how-do-i-pass-parameters-to-a-junit-test-from-ant

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!