如何从 Ant 将参数传递给 Junit 测试?

如何从 Ant 将参数传递给 Junit 测试?

问题描述:

我在 Ant 下使用 Junit 进行 Selenium 测试.我的测试用例需要读取文件其中包含测试数据(以完成数据驱动测试).我不介意在测试用例中嵌入文件名,但我希望有目录的名称数据文件存储在 build.xml 文件中.

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.

将类似信息从 build.xml 传递到测试用例的最佳方式是什么?使用 ant 属性是个好主意吗?是否可以从 build.xml 注入 Junit4 参数?

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?

junit 任务接受嵌套的 sysproperty 元素.

The junit task accepts nested sysproperty elements.

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

您可以使用 System.getProperty().