Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add lifecycle methods for parameterized containers #4352

Closed
2 tasks done
marcphilipp opened this issue Feb 27, 2025 · 1 comment · Fixed by #4366
Closed
2 tasks done

Add lifecycle methods for parameterized containers #4352

marcphilipp opened this issue Feb 27, 2025 · 1 comment · Fixed by #4366

Comments

@marcphilipp
Copy link
Member

marcphilipp commented Feb 27, 2025

Follow-up on #4320.

In addition to the existing @BeforeAll, @BeforeEach, @AfterEach, and @AfterAll lifecycle methods, we should add introduce @BeforeArgumentSet/@AfterArgumentSet annotations that can be declared on static (unless TestInstance.Lifecycle.PER_CLASS is used) methods of the test class that will be executed once per argument set before/after all test methods and nested classes in a @ParameterizedContainer class.

Since those methods are usually static, they won't have access to the resolved parameters. Therefore, and for compatibility with JUnit 4's @BeforeParams/@AfterParams methods, we should support injecting them as method parameters of those lifecycle methods.

Deliverables

  • Introduce @BeforeArgumentSet/@AfterArgumentSet lifecycle methods for @ParameterizedContainer classes
  • Add support for passing the resolved arguments of the current invocation to those lifecycle methods
@marcphilipp
Copy link
Member Author

Depends on #4320

@marcphilipp marcphilipp self-assigned this Feb 28, 2025
@marcphilipp marcphilipp added this to the 5.13.0-M1 milestone Feb 28, 2025
marcphilipp added a commit that referenced this issue Mar 5, 2025
This commit introduces two new annotations for 
``@ParameterizedClass`-specific lifecycle methods.
Methods annotated with ``@BeforeArgumentSet` or ``@AfterArgumentSet` are
called once before or after, respectively, each argument set the
parameterized class is invoked with. Depending on their
`injectArguments` annotation attribute, they may consume the
invocation's arguments, for example, to initialize them.

Resolves #4352.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment