How are Dynamic Tests different from Parameterized Tests in JUnit 5?

Yasin :

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.

Any ideas?

mfulton26 :

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). This is because one of the core principles for JUnit 5 is to "prefer extension points over features" (Core Principles · 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 5.0 M5 Milestone's theme is currently "dynamic containers and minor API changes". 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 (e.g. dynamic containers/tests) and then create and encourage 3rd parties to create extensions that leverage them (e.g. parameterized tests).

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=442901&siteId=1