Skip to content

Commit 08085ca

Browse files
committed
Fail when no tests are found
1 parent 84bc3fa commit 08085ca

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

src/main/java/de/donnerbart/split/TestSplit.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,12 @@ public void run() throws Exception {
6464
LOG.info("Working directory: {}", workingDirectory);
6565
final var testPaths = getPaths(workingDirectory, glob, excludeGlob);
6666
final var classNames = fileToClassName(testPaths, exitCodeConsumer);
67-
LOG.info("Found {} test classes", classNames.size());
67+
if (classNames.isEmpty()) {
68+
LOG.error("Found no test classes");
69+
exitCodeConsumer.accept(1);
70+
} else {
71+
LOG.info("Found {} test classes", classNames.size());
72+
}
6873

6974
final var testCases = new HashSet<TestCase>();
7075
if (junitGlob != null) {

src/test/java/de/donnerbart/split/TestSplitTest.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,24 @@ void run_withJUnit_secondSplit() throws Exception {
133133
assertThat(exitCode).hasNullValue();
134134
}
135135

136+
@Test
137+
void run_noTests() throws Exception {
138+
final var projectFolder = tmp.resolve("no-tests-project").resolve("src").resolve("main").resolve("java");
139+
140+
final var testSplit = new TestSplit(0,
141+
1,
142+
"**/no-tests-project/**/*Test.java",
143+
null,
144+
null,
145+
projectFolder,
146+
true,
147+
exitCode::set);
148+
testSplit.run();
149+
150+
assertThat(systemOut.getLinesNormalized()).isEmpty();
151+
assertThat(exitCode).hasValue(1);
152+
}
153+
136154
@Test
137155
void run_noPackage() throws Exception {
138156
final var projectFolder = tmp.resolve("no-package-project").resolve("src").resolve("main").resolve("java");

0 commit comments

Comments
 (0)