Java: include RepeatedTest, ParameterizedTest, TestFactory, and TestTemplate when identifying JUnit 5 test methods

This commit is contained in:
Jami Cogswell
2025-03-23 16:36:08 -04:00
parent 4d7bed6181
commit 35b647839c
9 changed files with 192 additions and 9 deletions

View File

@@ -113,11 +113,36 @@ class JUnitJupiterTestMethod extends Method {
}
/**
* A JUnit test class that contains at least one method annotated with
* `org.junit.jupiter.api.Test`.
* A JUnit 5 test method.
* A test method is defined by JUnit as "any instance method
* that is directly annotated or meta-annotated with `@Test`,
* `@RepeatedTest`, `@ParameterizedTest`, `@TestFactory`, or
* `@TestTemplate`."
* See https://junit.org/junit5/docs/current/user-guide/#writing-tests-definitions
*/
class JUnit5TestMethod extends Method {
JUnit5TestMethod() {
this instanceof JUnitJupiterTestMethod or
this.getAnAnnotation()
.getType()
.hasQualifiedName("org.junit.jupiter.api", ["RepeatedTest", "TestFactory", "TestTemplate"]) or
this.getAnAnnotation()
.getType()
.hasQualifiedName("org.junit.jupiter.params", "ParameterizedTest")
}
}
/**
* A JUnit 5 test class.
* A test class must contain at least one test method, and
* cannot be abstract.
* See https://junit.org/junit5/docs/current/user-guide/#writing-tests-definitions
*/
class JUnit5TestClass extends Class {
JUnit5TestClass() { this.getAMethod() instanceof JUnitJupiterTestMethod }
JUnit5TestClass() {
this.getAMethod() instanceof JUnit5TestMethod and
not this.isAbstract()
}
}
/**