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 ability to access the current repetition of a RepeatedTest from afterEach in a custom Extension #1884

Closed
vmassol opened this issue May 17, 2019 · 4 comments

Comments

@vmassol
Copy link

vmassol commented May 17, 2019

My use case:

  • At the end of each test, save a video of the test in a file.
  • It has to support the @RepeatedTest annotation and thus the computed file name must include the repetition index.

It seems the info is in RepeatedTestInvocationContext but there are 2 issues:

  1. I don't know how to get access to that object in my afterEach, i.e. from an ExtensionContext. I guess I could use instanceof on the parent but it seems it's a TestTemplateExtensionContext so it wouldn't even work (and it feels hacky ;))
  2. Even if I were able to get access to RepeatedTestInvocationContext it doesn't contain any API to get the current repetition. The only thing it offers is a custom displayName but having to parse that to get the repetition index doesn't feel right.

Related Issues

@marcphilipp
Copy link
Member

I agree that this would be useful. 👍

@cj-darius-lapunas
Copy link

cj-darius-lapunas commented Jul 8, 2019

This would be very useful for us, since we use a custom extension with log4j to separate test logs into different files.

Current workaround:

private static final Pattern REPEATED_TEST_PATTERN = Pattern.compile("^repetition (\\d+) of (\\d+)$");

private static String parseRepetition(ExtensionContext context) {
        String displayName = context.getDisplayName();
        Matcher matcher = REPEATED_TEST_PATTERN.matcher(displayName);
        if (matcher.matches()) {
            int charCount = matcher.group(2).length();
            int repetition = Integer.parseInt(matcher.group(1));
            String format = "%0" + charCount + "d";
            return String.format(format, repetition);
        } else {
            return null;
        }
    }

@stale
Copy link

stale bot commented May 13, 2021

This issue has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be automatically closed if no further activity occurs. Thank you for your contribution.

@stale stale bot added the status: stale label May 13, 2021
@stale
Copy link

stale bot commented Jun 3, 2021

This issue has been automatically closed due to inactivity. If you have a good use case for this feature, please feel free to reopen the issue.

@stale stale bot closed this as completed Jun 3, 2021
@marcphilipp marcphilipp removed this from the 5.8 Backlog milestone Jun 19, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants