What is RepeatedTest in JUnit 5?

What is RepeatedTest in JUnit 5?

1 Like

Hey Alex,

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:

  1. 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.
  2. RepeatedTest is not limited to primitive types as ParameterizedTest uses. We can use any object as a parameter in repeated test.
  3. RepeatedTest allows us to set default values for parameters, so if none are provided then these are used instead.
  4. RepeatedTest also supports nesting of repeated tests.

Hope it helps!

2 Likes

Hey @alex-walker, When I tried to find the answer for your question, I came across a well explained post(by Satish Varma), I thought it could be the best answer for your question.

Check: https://javabydeveloper.com/junit-5-repeated-tests-with-examples/

Please let me know if this helps.

1 Like

Thanks @shahzebh @imsamanthastewart, Your answers help a lot. Have a good day!