-
Notifications
You must be signed in to change notification settings - Fork 3.3k
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
Conversation
. 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(); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 + "]"; |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done.
Many thanks! |
Running the example from the Javadoc in Eclipse will show this 7-year-old bug: |
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
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.