Skip to content

Commit

Permalink
Classes containing @testtemplate methods are now detected as Test cla…
Browse files Browse the repository at this point in the history
…sses (#729)
  • Loading branch information
ledoyen authored and sbrannen committed Mar 12, 2017
1 parent cf4a63b commit f889ef8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ public class IsTestClassWithTests implements Predicate<Class<?>> {

private static final IsTestFactoryMethod isTestFactoryMethod = new IsTestFactoryMethod();

private static final Predicate<Method> isTestOrTestFactoryMethod = isTestMethod.or(isTestFactoryMethod);
private static final IsTestTemplateMethod isTestTemplateMethod = new IsTestTemplateMethod();

private static final Predicate<Method> isTestOrTestFactoryOrTestTemplateMethod = isTestMethod.or(
isTestFactoryMethod).or(isTestTemplateMethod);

private static final IsPotentialTestContainer isPotentialTestContainer = new IsPotentialTestContainer();

Expand All @@ -43,11 +46,11 @@ public boolean test(Class<?> candidate) {
if (!isPotentialTestContainer.test(candidate)) {
return false;
}
return hasTestOrTestFactoryMethods(candidate) || hasNestedTests(candidate);
return hasTestOrTestFactoryOrTestTemplateMethods(candidate) || hasNestedTests(candidate);
}

private boolean hasTestOrTestFactoryMethods(Class<?> candidate) {
return !ReflectionUtils.findMethods(candidate, isTestOrTestFactoryMethod).isEmpty();
private boolean hasTestOrTestFactoryOrTestTemplateMethods(Class<?> candidate) {
return !ReflectionUtils.findMethods(candidate, isTestOrTestFactoryOrTestTemplateMethod).isEmpty();
}

private boolean hasNestedTests(Class<?> candidate) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;
import org.junit.jupiter.api.TestTemplate;

public class IsTestClassWithTestsTests {

Expand All @@ -40,6 +41,10 @@ void classWithNestedTestCasesEvaluatesToTrue() {
assertTrue(isTestClassWithTests.test(ClassWithNestedTestCases.class));
}

@Test
void classWithTestTemplateEvaluatesToTrue() {
assertTrue(isTestClassWithTests.test(ClassWithTestTemplate.class));
}
}

//class name must not end with 'Tests', otherwise it would be picked up by the suite
Expand Down Expand Up @@ -81,3 +86,12 @@ void second() {

}
}

//class name must not end with 'Tests', otherwise it would be picked up by the suite
class ClassWithTestTemplate {

@TestTemplate
void first(int a) {
}

}

0 comments on commit f889ef8

Please sign in to comment.