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

Parameterized runner should name tests better than sequential numbers #44

Closed
anshnd opened this issue Nov 16, 2009 · 42 comments
Closed

Comments

@anshnd
Copy link

anshnd commented Nov 16, 2009

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):

  • call toString on first parameter
  • call the a newly added names attribute to Parameters annotation (with default empty names for compatibility)
    public String[] names() default {};
  • call a public, static (!) method annotated by newly-defined @testname
    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

@JThoennes
Copy link

How about this issue? The suggestions are good, when will you implement it / incorporate the patch?

Thanks, Jörg

@JThoennes
Copy link

See also issue 24 which talks about the same topic, but was entered by dsaff.

@jjunit2010
Copy link

Any more news on when this fix might be implemented?

@reccles
Copy link

reccles commented Feb 5, 2010

There appears to be some demand for this simple feature outside as well: http://stackoverflow.com/questions/650894/change-test-name-of-parameterized-tests

@Yishai
Copy link

Yishai commented Feb 5, 2010

As an additional (simpler) suggestion, how about just changing
@OverRide protected String testName(final FrameworkMethod method) {
return String.format("%s%s", method.getName(),
Arrays.toString(fParameterList.get(fParameterSetNumber)));
}

@dbt
Copy link

dbt commented Feb 19, 2010

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,
-dave

@ralfebert
Copy link

@JThoennes
Copy link

Could this patch merged into the next JUnit release, please?

And when will the next release happen?

@davidkarlsen
Copy link

+1

@kaipe
Copy link

kaipe commented Jan 16, 2011

I have released a framework that offers a solution to this problem:
http://callbackparams.org The test-class runner that will probably solve most cases where this problem arises is ...
http://callbackparams.org/project/api-javadoc/org/callbackparams/junit4/EnumRunner.html ... and for more complex cases the rest of the framework has a lot to offer.

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.

@mmakowski
Copy link

+1

3 similar comments
@soehalim
Copy link

soehalim commented Sep 7, 2011

+1

@elygre
Copy link

elygre commented Sep 20, 2011

+1

@binkley
Copy link

binkley commented Oct 12, 2011

+1

@davidkarlsen
Copy link

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?

@sivaram-psg
Copy link

+1

1 similar comment
@joelmheim
Copy link

+1

@stefanbirkner
Copy link
Contributor

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.

@jonfreedman
Copy link

+1

@stefanbirkner
Copy link
Contributor

I'm just waiting for pull request #348

@bsbodden
Copy link

+1

@RaviH
Copy link

RaviH commented Dec 20, 2011

+1 (guessing that's the way to vote it up?)

@Tibor17
Copy link
Contributor

Tibor17 commented Dec 21, 2011

+1

1 similar comment
@Jeanguitoune
Copy link

+1

@yurodivuie
Copy link

+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.

@slongoni
Copy link

+1

2 similar comments
@sharfah
Copy link

sharfah commented Jan 26, 2012

+1

@cwhite102
Copy link

+1

@veger
Copy link

veger commented Feb 20, 2012

+1

5 similar comments
@java-artisan
Copy link

+1

@lbuchy
Copy link

lbuchy commented Feb 22, 2012

+1

@mrmanc
Copy link

mrmanc commented Feb 29, 2012

+1

@ghost
Copy link

ghost commented Mar 1, 2012

+1

@mariusx
Copy link

mariusx commented Mar 2, 2012

+1

stefanbirkner added a commit to stefanbirkner/junit that referenced this issue Mar 2, 2012
.

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.
@jpfielding
Copy link

+2

@z3jiang
Copy link

z3jiang commented Mar 26, 2012

+1

1 similar comment
@avernet
Copy link

avernet commented Mar 29, 2012

+1

ebruchez pushed a commit to orbeon/junit that referenced this issue Mar 30, 2012
.

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.
dsaff added a commit that referenced this issue Apr 9, 2012
Add names for parameterized tests. Fixes #24 and #44.
@guyburton
Copy link

+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.

@stefanbirkner
Copy link
Contributor

The feature is implemented. See #393.

@dsaff Could you please close the issue.

@dsaff
Copy link
Member

dsaff commented Apr 12, 2012

Done.

@dsaff dsaff closed this as completed Apr 12, 2012
@java-artisan
Copy link

Many thanks indeed ! :-)

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