简体   繁体   English

JUnit 5 中的 TestNG @Factory 模拟

[英]TestNG @Factory analog in JUnit 5

In TestNG we can annotate test class constructor @Factory annotation and specify data provider for this factory like this:在 TestNG 中,我们可以注释测试类构造函数 @Factory 注释并为该工厂指定数据提供者,如下所示:

@Factory(dataProvider = "dataProviderName")

And TestNG create instance of test class for each object returned by data provider. TestNG 为数据提供者返回的每个对象创建测试类的实例。 In JUnit 5 I didn't found feature exactly like that.在 JUnit 5 中,我没有找到完全一样的功能。 My question is, how I can reproduce that behavior in JUnit 5?我的问题是,如何在 JUnit 5 中重现这种行为?

Thanks in advance for your help在此先感谢您的帮助

Please, read a guide about Dynamic tests - https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests-examples请阅读有关动态测试的指南 - https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests-examples

Also, dynamic tests can be parameterized (like data providers) with Sources - https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests-uri-test-source read this part of guide此外,可以使用 Sources 对动态测试进行参数化(如数据提供者) - https://junit.org/junit5/docs/current/user-guide/#writing-tests-dynamic-tests-uri-test-source阅读此部分指南的

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

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