What is RepeatedTest in JUnit 5?
RepeatedTest allows us to write tests which can be rerun automatically while we keep writing the tests. For example, if we want to test a class and it’s methods, we can run the same test against different data and different arguments. RepeatedTest is great to write automated acceptance tests for the functionality of your application.
RepeatedTest is similar to JUnit’s ParameterizedTest but it has some important differences:
- RepeatedTest gives us more control over the iteration. For example, we can assert that iteration should stop after a specific number of iterations or when an Exception is thrown or when a certain time is exceeded.
- RepeatedTest is not limited to primitive types as ParameterizedTest uses. We can use any object as a parameter in repeated test.
- RepeatedTest allows us to set default values for parameters, so if none are provided then these are used instead.
- RepeatedTest also supports nesting of repeated tests.
Hope it helps!
Please let me know if this helps.