Add support for JUnit 5 method naming
Tests that are annotated with org.junit.jupiter.api.Test were not recognized as unit tests. Provide detection for JUnit 5 style tests and also provide the possibility to customize the method naming regex similar to the existing ones.
This commit is contained in:
@ -35,6 +35,7 @@ public class MethodNamingConventionsRule extends AbstractNamingConventionRule<AS
|
|||||||
private final PropertyDescriptor<Pattern> nativeRegex = defaultProp("native").build();
|
private final PropertyDescriptor<Pattern> nativeRegex = defaultProp("native").build();
|
||||||
private final PropertyDescriptor<Pattern> junit3Regex = defaultProp("JUnit 3 test").defaultValue("test[A-Z0-9][a-zA-Z0-9]*").build();
|
private final PropertyDescriptor<Pattern> junit3Regex = defaultProp("JUnit 3 test").defaultValue("test[A-Z0-9][a-zA-Z0-9]*").build();
|
||||||
private final PropertyDescriptor<Pattern> junit4Regex = defaultProp("JUnit 4 test").build();
|
private final PropertyDescriptor<Pattern> junit4Regex = defaultProp("JUnit 4 test").build();
|
||||||
|
private final PropertyDescriptor<Pattern> junit5Regex = defaultProp("JUnit 5 test").build();
|
||||||
|
|
||||||
|
|
||||||
public MethodNamingConventionsRule() {
|
public MethodNamingConventionsRule() {
|
||||||
@ -45,6 +46,11 @@ public class MethodNamingConventionsRule extends AbstractNamingConventionRule<AS
|
|||||||
definePropertyDescriptor(nativeRegex);
|
definePropertyDescriptor(nativeRegex);
|
||||||
definePropertyDescriptor(junit3Regex);
|
definePropertyDescriptor(junit3Regex);
|
||||||
definePropertyDescriptor(junit4Regex);
|
definePropertyDescriptor(junit4Regex);
|
||||||
|
definePropertyDescriptor(junit5Regex);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isJunit5Test(ASTMethodDeclaration node) {
|
||||||
|
return node.isAnnotationPresent("org.junit.jupiter.api.Test");
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isJunit4Test(ASTMethodDeclaration node) {
|
private boolean isJunit4Test(ASTMethodDeclaration node) {
|
||||||
@ -85,6 +91,8 @@ public class MethodNamingConventionsRule extends AbstractNamingConventionRule<AS
|
|||||||
}
|
}
|
||||||
} else if (node.isStatic()) {
|
} else if (node.isStatic()) {
|
||||||
checkMatches(node, staticRegex, data);
|
checkMatches(node, staticRegex, data);
|
||||||
|
} else if (isJunit5Test(node)) {
|
||||||
|
checkMatches(node, junit5Regex, data);
|
||||||
} else if (isJunit4Test(node)) {
|
} else if (isJunit4Test(node)) {
|
||||||
checkMatches(node, junit4Regex, data);
|
checkMatches(node, junit4Regex, data);
|
||||||
} else if (isJunit3Test(node)) {
|
} else if (isJunit3Test(node)) {
|
||||||
|
Reference in New Issue
Block a user