RepeatedTest with @TestInstance(PER_CLASS) yields varying instance IDs
27K reputation · 23 Feb 2024, 10:03 UTC
Determine whether JUnit 5’s @RepeatedTest annotation creates a new test instance for each repetition when the test class is annotated with @TestInstance(Lifecycle.PER_CLASS).
The current specification does not explicitly state if the same instance should be reused across repetitions, and the behavior is still under discussion in the project’s issue tracker. Relying on the observed instance‑creation pattern may lead to flaky tests if the API changes in a future release.
Does JUnit 5 currently instantiate a new test object for each repetition under @TestInstance(PER_CLASS)? If the instance is reused, what conditions trigger reuse? Is there any version‑specific guarantee that the behavior will remain stable?