Pragmatists/JUnitParams

Adding a possibility to define custom TestCaseNamingStrategy

Opened this issue · 1 comments

Hello!

I thought it would be awesome to be able to replace TestCaseNamingStrategy to my liking. I would like to be able to define my custom strategy that uses custom macros. The main reason is to be able to get unique object's attribute to be printed out in the test case name.

Let's say I have three objects as parameters:
Person { "id": "id-1", "fullName": "person 1"}, Person { "id": "id-2", "fullName": "person 2"}, Person { "id": "id-3", "fullName": "person 3"}

Those objects are added to my parameterised test using annotation @Parameter. I would like to be able to put following as definition for the test case name:
@TestCaseName("[{PERSON_ID}] {PERSON_FULLNAME}")
The wanted outcome would be:
[id-1] person 1 PASSED

I propose to be able to define naming strategy which would be used for parametrised test. Maybe this would be feasible solutions:
@TestCaseName({value = "[{PERSON_ID}] {PERSON_FULLNAME}", strategy=CustomTestCaseNamingStrategy.class)
or
@Parameter({value|source|method|named = "", strategy=CustomTestCaseNamingStrategy.class})

Currently implemented solution (CustomNamingStrategy is implemented from TestCaseNamingStrategy):
@TestCaseNameStrategy(CustomNamingStrategy.class)

I could probably try to contribute to implement this issue. I decided to create this issue because I saw that test case naming strategy is used in multiple classes. In order to adjust code to my liking, I would basically need to copy all your classes and make my own. Let me know what do you thing about this.

EDIT: What is actual motivation for such feature? This feature would be useful if your tests are so dynamic that they accept particular list of objects. The object from mentioned list would have unique attribute that will make it easier to detect which test case failed instead of counting it by default index number. Using unique attribute would make searching for failed tests easier.

@plipinski @woprzech

If you could take a look at this issue, I would appreciate it. The proposed solution probably needs additional comments.

P.S. I actually implemented it already, I can create pull request if it is OK.

Repo: https://github.com/danijelsokac-ingemark/JUnitParamsNamingStrat/tree/danijelsokac-ingemark-defNamingStrat

The naming strategy class could probably be defined differently to enable less code being copied. This is not implemented yet but I could try to handle this too. This was just a quick implementation for needed feature.