When you run a JUnit 4 ParameterizedTest with the Eclipse TestRunner, the graphical representation is rather dumb: for each test you have a node called [0]
, [1]
, etc.
Is it possible give the tests [0]
, [1]
, etc. explicit names? Implementing a toString
method for the tests does not seem to help.
(This is a follow-up question to JUnit test with dynamic number of tests.)
There's no hint that this feature is or will be implemented. I would request this feature because it's nice to have.
JUnit4 now allows specifying a name attribute to the Parameterized annotation, such that you can specify a naming pattern from the index and toString methods of the arguments. E.g.:
If you use JUnitParams library (as I have described here), the parameterized tests will have their stringified parameters as their own default test names.
Moreover, you can see in their samples, that JUnitParams also allows you to have a custom test name by using
@TestCaseName
:A code-less though not that comfortable solution is to pass enough context information to identify the test in assert messages. You will still see just testXY[0] failed but the detailed message tells you which one was that.
I think there's nothing built in in jUnit 4 to do this.
I've implemented a solution. I've built my own
Parameterized
class based on the existing one:To be used like:
This implies that I instantiate the test class earlier. I hope this won't cause any errors ... I guess I should test the tests :)