如何从 Ant 将参数传递给 Junit 测试? [英] How do I pass parameters to a Junit test from Ant?

查看:35
本文介绍了如何从 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().

这篇关于如何从 Ant 将参数传递给 Junit 测试?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆