Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find all 'public void' methods not annotated with '@Test'

I want to perform structural search on my tests to detect all methods that look like tests but are not annotated with @Test.

I tried with this pattern with no success (no matching code found):

@$Annotation$ public void $method$()

$Annotation$ - text like: ^Test$, min occurs: 0, max occurs: 0
$method$ - text like: should|test, min occurs: 1, max occurs: 1

What am I doing wrong?

like image 546
Michal Kordas Avatar asked Mar 16 '26 19:03

Michal Kordas


1 Answers

Seems, you have to try to provide a class with your pattern too, as it's done in templates:

class $Class$ {
  @$Annotation$( )
  $MethodType$ $MethodName$($ParameterType$ $ParameterName$);
}

Furthermore, you have to change the $method$ variable to something like should.*|test.* to accept not a whole words only.

I've tested it with IntelliJ Idea 15, it's working for the methods like:

public void testSomething() {

}

public void shouldSomething() {

}

only if the $Class$ is provided in search template and the method names regexes contain .* to match any method, which name begins with test or should.

like image 52
Stanislav Avatar answered Mar 18 '26 08:03

Stanislav