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 names for parameterized tests. Fixes #24 and #44. #393

Merged
merged 4 commits into from
Apr 9, 2012

Conversation

stefanbirkner
Copy link
Contributor

In order that you can easily identify individual test, you may provide a name for the Parameters annotation.
@parameters(name="my test")
This name is allowed to contain placeholders, which are replaced at runtime. The placeholders are

  • {index} - the current parameter index
  • {0} - the first parameter
  • {1} - the second parameter
  • ... - the other parameters
    If you don't use the name parameter, then the current parameter index is used as name.

Example:
When you use @parameters(name="fib({0})={1}") with the Fibonacci example, then you get test names like "fib(3)=2".

This feature is based on the work of Dimitar Dimitrov (pull request#145). Thank you.

.

In order that you can easily identify individual test, you may provide
a name for the Parameters annotation.
 @parameters(name="my test")
This name is allowed to contain placeholders, which are replaced at
runtime. The placeholders are
* {index} - the current parameter index
* {0} - the first parameter
* {1} - the second parameter
* ... - the other parameters
If you don't use the name parameter, then the current parameter index
is used as name.

Example:
When you use @parameters(name="fib({0})={1}") with the Fibonacci
example, then you get test names like "fib(3)=2".

This feature is based on the work of Dimitar Dimitrov (pull request
junit-team#145).
Thank
you.
@Override
protected Annotation[] getRunnerAnnotations() {
return new Annotation[0];
}
}

private static final List<Runner> NO_RUNNERS= Collections
.<Runner> emptyList();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What column limit are you formatting with? Some of these lines seem to be wrapped pretty early

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use the standard settings: org.eclipse.jdt.core.formatter.lineSplit=80.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK.

String finalPattern= namePattern.replaceAll("\\{index\\}",
Integer.toString(index));
String name= MessageFormat.format(finalPattern, parameters);
return "[" + name + "]";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should the added brackets be mentioned in the javadoc?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

dsaff added a commit that referenced this pull request Apr 9, 2012
Add names for parameterized tests. Fixes #24 and #44.
@dsaff dsaff merged commit 3a5c9f2 into junit-team:master Apr 9, 2012
@dsaff
Copy link
Member

dsaff commented Apr 9, 2012

Many thanks!

@marcphilipp
Copy link
Member

Running the example from the Javadoc in Eclipse will show this 7-year-old bug:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=102512
:-/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants