简体   繁体   English

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

[英]How to dynamically add a test to test suite in JUnit 4?

I recently read ( link text ) about a way to statically add tests to test suite in JUnit 4? 我最近阅读( 链接文本 )关于在JUnit 4中静态添加测试到测试套件的方法? What about a dynamic way, ie how to add a test class if its name is known not earlier than at run-time, eg its name is read from XML file? 那么动态的方法呢,即如果知道其名称不早于运行时的名称,如何添加测试类,例如从XML文件中读取其名称?

I know how to do it. 我知道该怎么做。 I can use JUnitExt library ( http://junitext.sourceforge.net ). 我可以使用JUnitExt库( http://junitext.sourceforge.net )。 It supports "declarative test configurations (as provided by TestNG)". 它支持“声明性测试配置(由TestNG提供)”。 See junitext.sourceforge.net/tutorial.html (How to parameterize tests using XML). 请参阅junitext.sourceforge.net/tutorial.html(如何使用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. JUnitCore类允许您传入要运行的类列表。 These can be read in from anywhere you like including XML. 这些可以从任何你喜欢的地方读入,包括XML。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM