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

Adding a possibility to define custom TestCaseNamingStrategy #179

Open
danijelsokac-ingemark opened this issue Feb 28, 2023 · 1 comment

Comments

@danijelsokac-ingemark
Copy link

danijelsokac-ingemark commented Feb 28, 2023

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.

@danijelsokac-ingemark
Copy link
Author

danijelsokac-ingemark commented Mar 1, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant