Skip to content

Commit 8bfa0f2

Browse files
committed
Make sure we have a test compilation unit before going further
Also optimize things a bit when we don't have tests around. Fixes #47794 (cherry picked from commit 0243281)
1 parent f979492 commit 8bfa0f2

File tree

1 file changed

+32
-13
lines changed

1 file changed

+32
-13
lines changed

core/deployment/src/main/java/io/quarkus/deployment/dev/testing/JunitTestRunner.java

Lines changed: 32 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -569,21 +569,23 @@ private DiscoveryResult discoverTestClasses() {
569569
//for now this is out of scope, we are just going to do annotation based discovery
570570
//we will need to fix this sooner rather than later though
571571

572+
if (moduleInfo.getTest().isEmpty()) {
573+
return DiscoveryResult.EMPTY;
574+
}
575+
572576
//we also only run tests from the current module, which we can also revisit later
573577
Indexer indexer = new Indexer();
574-
moduleInfo.getTest().ifPresent(test -> {
575-
try (Stream<Path> files = Files.walk(Paths.get(test.getClassesPath()))) {
576-
files.filter(s -> s.getFileName().toString().endsWith(".class")).forEach(s -> {
577-
try (InputStream in = Files.newInputStream(s)) {
578-
indexer.index(in);
579-
} catch (IOException e) {
580-
throw new RuntimeException(e);
581-
}
582-
});
583-
} catch (IOException e) {
584-
throw new RuntimeException(e);
585-
}
586-
});
578+
try (Stream<Path> files = Files.walk(Paths.get(moduleInfo.getTest().get().getClassesPath()))) {
579+
files.filter(s -> s.getFileName().toString().endsWith(".class")).forEach(s -> {
580+
try (InputStream in = Files.newInputStream(s)) {
581+
indexer.index(in);
582+
} catch (IOException e) {
583+
throw new RuntimeException(e);
584+
}
585+
});
586+
} catch (IOException e) {
587+
throw new RuntimeException(e);
588+
}
587589

588590
Index index = indexer.complete();
589591
//we now have all the classes by name
@@ -699,6 +701,20 @@ private DiscoveryResult discoverTestClasses() {
699701
unitTestClasses.add(name);
700702
}
701703

704+
// if we didn't find any test classes, let's return early
705+
// Make sure you also update the logic for the non-empty case above if you adjust this part
706+
if (testType == TestType.ALL) {
707+
if (unitTestClasses.isEmpty() && quarkusTestClasses.isEmpty()) {
708+
return DiscoveryResult.EMPTY;
709+
}
710+
} else if (testType == TestType.UNIT) {
711+
if (unitTestClasses.isEmpty()) {
712+
return DiscoveryResult.EMPTY;
713+
}
714+
} else if (quarkusTestClasses.isEmpty()) {
715+
return DiscoveryResult.EMPTY;
716+
}
717+
702718
List<Class<?>> itClasses = new ArrayList<>();
703719
List<Class<?>> utClasses = new ArrayList<>();
704720

@@ -809,6 +825,7 @@ public String apply(Class<?> aClass) {
809825
}
810826
}
811827

828+
// Make sure you also update the logic for the empty case above if you adjust this part
812829
if (testType == TestType.ALL) {
813830
//run unit style tests first
814831
//before the quarkus tests have started
@@ -1271,6 +1288,8 @@ public FilterResult apply(TestDescriptor testDescriptor) {
12711288

12721289
static class DiscoveryResult implements AutoCloseable {
12731290

1291+
private final static DiscoveryResult EMPTY = new DiscoveryResult(null, List.of());
1292+
12741293
final QuarkusClassLoader classLoader;
12751294
final List<Class<?>> testClasses;
12761295

0 commit comments

Comments
 (0)