如何在 JUnit 4 中动态添加测试到测试套件?

发布于 2024-09-04 07:15:09 字数 218 浏览 1 评论 0原文

我最近阅读了(链接文本)关于一种方法将测试静态添加到 JUnit 4 中的测试套件中?动态方式怎么样,即如果测试类的名称不早于运行时已知,例如从 XML 文件读取其名称,如何添加测试类?

I recently read (link text) about a way to statically add tests to test suite in JUnit 4? What about a dynamic way, i.e. how to add a test class if its name is known not earlier than at run-time, e.g. its name is read from XML file?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

全部不再 2024-09-11 07:15:09

我知道该怎么做。我可以使用 JUnitExt 库 (http://junitext.sourceforge.net)。它支持“声明性测试配置(由 TestNG 提供)”。请参阅 junitext.sourceforge.net/tutorial.html(如何使用 XML 参数化测试)。

I know how to do it. I can use JUnitExt library (http://junitext.sourceforge.net). It supports "declarative test configurations (as provided by TestNG)". See junitext.sourceforge.net/tutorial.html (How to parameterize tests using XML).

浅紫色的梦幻 2024-09-11 07:15:09

我不知道如何添加到现有套件,但您可以在运行时创建自己的套件。 JUnitCore 类允许您传入要运行的类的列表。这些可以从您喜欢的任何地方读取,包括 XML。

I don't know of a way to add to an existing suite, but you can create your own suite at runtime. The JUnitCore class lets you pass in a list of classes you want run. These can be read in from anywhere you like including XML.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文