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
New Check: AnnotatedMethodNameCheck to check method names of annotated (test) methods #14746
Comments
Could you please explain a bit on where a specific pattern is mentioned for annotated test methods?
I agree we may use this by convention (even in our code) but enforcing this on all users is a major debate.
Could you please share examples of such style schemes? |
The Google Style Guide doesn't specify a pattern for test methods:
However it suggests that a pattern may be used:
Both the pattern and annotations are properties which can be adjusted to the user's needs.
Test methods schould be named "test" + method name.
There are some special methods with specific annotations which should always be named the same:
|
I have understood your vision previously. Please provide sources/links to such code styles that support your statement above
A bit of clarity here.. the new check wants to focus only on targeted methods ? (I don't think this is what google style implied) checkstyle/src/main/java/com/puppycrawl/tools/checkstyle/checks/naming/MethodNameCheck.java Lines 68 to 70 in 4fe8118
|
I want only certain annotated methods to be checked. The current MethodName Check doesn't allow that functionality. It will always check methods whether annotated or not. Actually, the best thing to do would be to extend the current MethodName Check to be able to filter only certain annotated methods. Then a new Check won't be necessary. I suppose this issue could be changed to an extension for MethodName then?
I have provided a link to the Google conventions, which mentions a pattern. I cannot link to internal uni project conventions tho. But I am sure there are many conventions for test method out there. Regardless, I think this is a useful feature, allowing users more control. |
This doesn't need a new check. We make use of certain properties to restrict/limit/enhance/extend existing check accordingly.
This is where we are stumbling around.. From what I know of the project, we don't introduce new functionalities based on assumptions or very few uni conventions. For a new functionality to be implemented, it needs to be backed up by a reliable code style scheme. I hope you understand what I mean, we can't force users to follow something that is limited to few unis or random conventions.
This, however is not in my power to decide, let's wait for the maintainers' opinion. |
conceptually, after shallow review, I am good with proposal. can this be a solution https://checkstyle.org/checks/coding/matchxpath.html#MatchXpath ? you can find bunch of example in our issue tracker and discussions, like #12975 (comment) |
Theoretically yes, we should be able to evaluate an xpath query that matches targeted node |
I believe so, yes. I have not looked much into Xpaths, but they seem very powerful. In that case, I think it might be useful to mention them in the documentation more explicitly. I had the impression I would have to change or add a new Check. This would keep users from implementing checks that Xpath could accomplish easily.
Does that mean the functionality I described should be added to Checkstlye? Or it should not, since Xpath could do the same? |
Try to make it by xpath first, such attempt usually shows and items that xpath is not able to do. So reason for new Check will be more explicit. |
I'd like to a request a new check that makes sure the method names of annotated methods adhere to a specific pattern.
How it works Now:
Check MethodName allows to check that method names conform to a specified pattern. However, it can not differentiate between annotated methods.
Is your feature request related to a problem? Please describe.
Some coding conventions, like the one used for my uni project, set rules for the naming of test methods, typically annotated with
@Test
.The Google Conventions also shows an example of a specific pattern for test methods.
By implementing the proposed Check, those conventions could be enforced via Checkstyle.
Describe the solution you'd like
config.xml
annotations
: All annotations that will trigger the checkmethodPattern
: The regex pattern the name of an annotated method must adhere toTest.java
Expected Output
Additional context
Another Example shows how naming conventions for other testing Annotations can be enforced. Suppose
@BeforeEach
methods shall be namedsetUp()
:config.xml
Example 1
The naming convention is followed.
Example 2
The naming convention is not followed.
Implementation Proposal
I have already implemented a possible solution for this problem. This may be useful as starting point for creating a solution for the Checkstyle project.
The text was updated successfully, but these errors were encountered: