简体   繁体   中英

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?

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 .

You could also try the Old style JUnit test method in JUnit 4 class inspection. This inspection detects methods that look like tests, but are not annotated with @Test .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM