-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Parameterized runner should name tests better than sequential numbers #44
Comments
How about this issue? The suggestions are good, when will you implement it / incorporate the patch? Thanks, Jörg |
See also issue 24 which talks about the same topic, but was entered by dsaff. |
Any more news on when this fix might be implemented? |
There appears to be some demand for this simple feature outside as well: http://stackoverflow.com/questions/650894/change-test-name-of-parameterized-tests |
As an additional (simpler) suggestion, how about just changing |
From my deployment experience (I forked Parameterized internally to my project and extended it with similar functionality), using toString or non-static testName() functions were suboptimal, and using a fixed portion of the parameters list (either the first parameter or all of them) was also not useful. My preferred solution was to support an annotated static method that took the same arguments as the constructor and returned a string, and fall back to the test number if that didn't work. I'm happy to get the (fairly trivial) patch open sourced if that would help solve this problem. Thanks, |
Could this patch merged into the next JUnit release, please? And when will the next release happen? |
+1 |
I have released a framework that offers a solution to this problem: The key feature in regard to this issue is that tests are named by the overridden method java.lang.Object#toString(), which for enum-constants happen to return the name of the constant. If the enum-constant name won't do it is of course still possible to override java.lang.Object#toString() explicitly for those constants that need more verbose test-names. Anyhow, I think that a solution that does not rely on the toString()-method is simply not very elegant. |
the source code posted here worked perfectly here are the direct links to the source code: |
+1 |
3 similar comments
+1 |
+1 |
+1 |
Cmon! Why can't you apply this Kent? You even have ready patches and the issue is ancient. Isn't good naming part of cleancode and TDD practices - or do we simply have to dump junit for testng? |
+1 |
1 similar comment
+1 |
I like Dave's idea of a label method. It may look like @Label
public String labelForParameters(Object... parameters) {
...
} Hopefully there's time today or tomorrow evening to implement this. |
+1 |
I'm just waiting for pull request #348 |
+1 |
+1 (guessing that's the way to vote it up?) |
+1 |
1 similar comment
+1 |
+1. We've started keeping our own version of Parameterized to fix this problem, but it would be great to have this supported from the source. |
+1 |
2 similar comments
+1 |
+1 |
+1 |
5 similar comments
+1 |
+1 |
+1 |
+1 |
+1 |
. 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.
+2 |
+1 |
1 similar comment
+1 |
. 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.
+1 we have used a fork of Parameterized to implement this feature. We have also made the TestClassRunnerForParameters protected, and it is created by a protected method to allow extension of Parameterized within another implementation of Suite. |
Done. |
Many thanks indeed ! :-) |
Right now the test names are named sequentially 0,1, etc in Parameterized:
@OverRide
protected String getName() {
return String.format("[%s]", fParameterSetNumber);
}
@OverRide
protected String testName(final Method method) {
return String.format("%s[%s]", method.getName(), fParameterSetNumber);
}
It would help if the data themselves were to be used in determining the name. Proposed alternatives for name (which has to be determinited statically before Test is instantiated):
public String[] names() default {};
and accepting the same arguments as the constructor
I can provide (again) a patch. This issue was tracked as http://sourceforge.net/tracker/?func=detail&atid=365278&aid=1742040&group_id=15278 and https://sourceforge.net/tracker/?func=detail&atid=365278&aid=1630834&group_id=15278
I can submit a patch if needed
The text was updated successfully, but these errors were encountered: