Rename this method name to match the regular expression '^[a-z][a-zA-Z0-9]*$'

Hi all,

I have the following reference message **(Rename this method name to match the regular expression ^[a-z][a-zA-Z0-9]*$')** in the SonarQube rules, I come to your help since I need to know how to do it from Sonar so that:

Allow test classes (src/test/java) to allow _ (Underscores) in method names, in order to better read test names.

please any suggestion.

Thank you


Welcome to the community!

To write a regex that allows only test methods to have underscores in names, but not other methods, we’ll need a way to identify that we’re looking at a test method name. Specifically, do your test method names have “test” in them? Because from this rule/regex, we can’t look at annotations, or packages or anything else. Just the names.

As an example, if all the test method names start with test_ then the regex might look like

That allows method names that start with test to have an underscore immediately after test, but nowhere else.

So, can you fully list your rules?