2525import org .gradle .api .file .FileTree ;
2626import org .gradle .api .tasks .Input ;
2727import org .gradle .api .tasks .OutputFile ;
28- import org .gradle .api .tasks .SkipWhenEmpty ;
2928import org .gradle .api .tasks .TaskAction ;
3029import org .gradle .api .tasks .testing .Test ;
3130import org .gradle .api .tasks .util .PatternFilterable ;
@@ -103,6 +102,22 @@ public void doCheck() throws IOException {
103102 final Map <String , Set <File >> classFilesPerRandomizedTestingTask = classFilesPerRandomizedTestingTask (allTestClassFiles );
104103 final Map <String , Set <File >> classFilesPerGradleTestTask = classFilesPerGradleTestTask ();
105104
105+ Map <String , Set <Class <?>>> testClassesPerTask =
106+ Stream .concat (
107+ classFilesPerGradleTestTask .entrySet ().stream (),
108+ classFilesPerRandomizedTestingTask .entrySet ().stream ()
109+ )
110+ .collect (
111+ Collectors .toMap (
112+ Map .Entry ::getKey ,
113+ entry -> entry .getValue ().stream ()
114+ .map (classes ::get )
115+ .filter (implementsNamingConvention )
116+ .collect (Collectors .toSet ())
117+ )
118+ );
119+
120+
106121 problems = collectProblems (
107122 checkNoneExists (
108123 "Test classes implemented by inner classes will not run" ,
@@ -118,6 +133,16 @@ public void doCheck() throws IOException {
118133 .filter (this ::seemsLikeATest )
119134 .filter (implementsNamingConvention .negate ())
120135 ),
136+ collectProblems (
137+ testClassesPerTask .entrySet ().stream ()
138+ .map ( entry ->
139+ checkAtLeastOneExists (
140+ "test class in " + entry .getKey (),
141+ entry .getValue ().stream ()
142+ )
143+ )
144+ .collect (Collectors .joining ())
145+ ),
121146 checkNoneExists (
122147 "Test classes are not included in any enabled task (" +
123148 Stream .concat (
@@ -215,7 +240,6 @@ private Class<? extends Task> getRandomizedTestingTask() {
215240 }
216241
217242 @ Input
218- @ SkipWhenEmpty
219243 public Map <String , File > getTestClassNames () {
220244 if (testClassNames == null ) {
221245 testClassNames = Boilerplate .getJavaSourceSets (getProject ()).getByName ("test" ).getOutput ().getClassesDirs ()
@@ -243,6 +267,14 @@ private String checkNoneExists(String message, Stream<? extends Class<?>> stream
243267 }
244268 }
245269
270+ private String checkAtLeastOneExists (String message , Stream <? extends Class <?>> stream ) {
271+ if (stream .findAny ().isPresent ()) {
272+ return "" ;
273+ } else {
274+ return "Expected at least one " + message + ", but found none.\n " ;
275+ }
276+ }
277+
246278 private boolean seemsLikeATest (Class <?> clazz ) {
247279 try {
248280 ClassLoader classLoader = clazz .getClassLoader ();
0 commit comments