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

Make invocation index for @ParameterizedTest available to test author #1668

Closed
Gabology opened this issue Nov 8, 2018 · 15 comments · Fixed by #3085
Closed

Make invocation index for @ParameterizedTest available to test author #1668

Gabology opened this issue Nov 8, 2018 · 15 comments · Fixed by #3085

Comments

@Gabology
Copy link

Gabology commented Nov 8, 2018

Overview

The invocation index of a parameterized test is accessible for templating when setting the display name of the test.

When it comes to accessing the invocation index using TestInfo it is not possible as it looks like the TestInfo implementation for @ParameterizedTest is of the default type. I would expect to get an RepetitionInfo instance so that I can access the invocation index programmatically.

Related Issues

@sbrannen
Copy link
Member

sbrannen commented Nov 8, 2018

FYI: this is closely related to #944.

@sbrannen sbrannen changed the title Getting invocation index for ParameterizedTests Supply invocation index for @ParameterizedTest to test author Nov 8, 2018
@sbrannen sbrannen added this to the 5.4 M1 milestone Nov 8, 2018
@sbrannen
Copy link
Member

sbrannen commented Nov 8, 2018

Tentatively slated for 5.4 M1 for team discussion

@mschechter-bellese
Copy link

It would also be helpful to have the index available in the ExtensionContext, so that it can be used via the @EnabledIf / @DisabledIf handler method.

@marcphilipp
Copy link
Member

A non-intrusive way of adding this would be to add the invocation index to ArgumentsAccessor.

@Gabology @mschechter-bellese Would that work in your use case?

@marcphilipp
Copy link
Member

marcphilipp commented May 13, 2021

Tentatively slated for 5.8 M2 solely for the purpose of team discussion.

@marcphilipp marcphilipp modified the milestones: 5.8 Backlog, 5.8 M2 May 13, 2021
@mschechter-bellese
Copy link

A non-intrusive way of adding this would be to add the invocation index to ArgumentsAccessor.

@Gabology @mschechter-bellese Would that work in your use case?

Would that make it available to the methods implemented for @EnabledIf / @DisabledIf, so that I can skip specific indexes when running a parameterized test? If so, I think the ArgumentsAccessor would work.

@marcphilipp
Copy link
Member

Would that make it available to the methods implemented for @EnabledIf / @DisabledIf, so that I can skip specific indexes when running a parameterized test?

No, ExecutionConditions are currently only evaluated at the method level, not the invocation level so I think that would be a separate issue.

@mschechter-bellese
Copy link

Would that make it available to the methods implemented for @EnabledIf / @DisabledIf, so that I can skip specific indexes when running a parameterized test?

No, ExecutionConditions are currently only evaluated at the method level, not the invocation level so I think that would be a separate issue.

Yes, that makes sense. I think I would need a different solution, then. Could you please let me know if there's an existing issue that covers this?

@marcphilipp
Copy link
Member

I think #1139 is closely related.

@mschechter-bellese
Copy link

I think #1139 is closely related.

Thanks!

@marcphilipp
Copy link
Member

Team decision: Add ArgumentsAccessor.getInvocationIndex().

@marcphilipp
Copy link
Member

@Gabology @mschechter-bellese Would one of you be interested in submitting a PR for this?

@marcphilipp marcphilipp modified the milestones: 5.8 M2, 5.x Backlog May 14, 2021
@mschechter-bellese
Copy link

@marcphilipp,

I am currently more focused on making the invocation index available to @DisabledIf / @EnabledIf consumers via #1139.

Quick question: if the invocation index is to be accessible from the ArgumentsAccessor, how is the invocation index value provided during instantiation? It appears that the invocation index is only available as an AtomicInteger in ParameterizedTestExtension.provideTestTemplateInvocationContexts, so I'm probably missing something.

@marcphilipp
Copy link
Member

Quick question: if the invocation index is to be accessible from the ArgumentsAccessor, how is the invocation index value provided during instantiation? It appears that the invocation index is only available as an AtomicInteger in ParameterizedTestExtension.provideTestTemplateInvocationContexts, so I'm probably missing something.

From there it needs to be passed to ParameterizedTestInvocationContext, ParameterizedTestParameterResolver, and finally ParameterizedTestMethodContext.resolve.

@marcphilipp marcphilipp removed this from the 5.x Backlog milestone Jun 19, 2021
@ghost ghost mentioned this issue Dec 5, 2021
7 tasks
@ghost
Copy link

ghost commented Dec 5, 2021

I have the ArgumentsAccessor.getInvocationIndex() idea working on my fork. I'll raise a PR for it.

@marcphilipp marcphilipp linked a pull request Dec 5, 2021 that will close this issue
7 tasks
@juliette-derancourt juliette-derancourt added this to the 5.10.0-M1 milestone Nov 14, 2022
@sbrannen sbrannen changed the title Supply invocation index for @ParameterizedTest to test author Supply invocation index for @ParameterizedTest to test author Apr 16, 2023
@sbrannen sbrannen changed the title Supply invocation index for @ParameterizedTest to test author Make invocation index for @ParameterizedTest available to test author Apr 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment