简体   繁体   English

动态测试与JUnit 5中的参数化测试有何不同?

[英]How are Dynamic Tests different from Parameterized Tests in JUnit 5?

Almost all the examples of dynamic tests that I have seen, can be reworked and written using parameterized tests. 几乎所有我见过的动态测试的例子都可以使用参数化测试进行重写和编写。 So, which is a practical scenario where the Dynamic tests are the only option, or at least, better suitable than the parameterized tests. 因此,这是一个实际场景,其中动态测试是唯一的选择,或者至少比参数化测试更合适。

The only "truly" dynamic test example in JUnit 5 docs is not practical. JUnit 5文档中唯一的“真正”动态测试示例并不实用。

Any ideas? 有任何想法吗?

Unlike DynamicTest , ParameterizedTest is not part of the core junit-jupiter-api but is in a separate artifact named junit-jupiter-params (see 3.12.1. Required Setup ). DynamicTest不同, ParameterizedTest不是核心junit-jupiter-api一部分,而是在一个名为junit-jupiter-params的单独工件中(参见3.12.1。必需的设置 )。 This is because one of the core principles for JUnit 5 is to "prefer extension points over features" ( Core Principles · junit-team/junit5 Wiki ). 这是因为JUnit 5的核心原则之一是“更喜欢扩展点而不是功能”( 核心原则·junit-team / junit5 Wiki )。

The JUnit Jupiter API defines how to create and register dynamic tests as an extension point to JUnit while JUnit Jupiter Params defines a higher-level API for defining parameterized tests. JUnit Jupiter API定义了如何创建和注册动态测试作为JUnit的扩展点,而JUnit Jupiter Params定义了用于定义参数化测试的更高级API。

JUnit 5.0 M5 Milestone 's theme is currently "dynamic containers and minor API changes". JUnit 5.0 M5 Milestone的主题目前是“动态容器和次要API更改”。 With these expected changes test developers will be able to not only create dynamic tests but trees of dynamic tests (dynamic containers containing other dynamic containers and/or tests) which is something that cannot currently be done with paramterized tests. 通过这些预期的更改,测试开发人员不仅可以创建动态测试,还可以创建动态测试树(包含其他动态容器和/或测试的动态容器),这是目前无法通过参数化测试完成的。 Such will prove, I think, very useful for creating specification-like tests. 我认为,这将证明对创建类似规范的测试非常有用。

In short, the idea as I understand it is to first release core extension points via "low-level" APIs (eg dynamic containers/tests) and then create and encourage 3rd parties to create extensions that leverage them (eg parameterized tests). 简而言之,我理解的想法是首先通过“低级”API(例如动态容器/测试)发布核心扩展点,然后创建并鼓励第三方创建利用它们的扩展(例如参数化测试)。

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

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