Skip to content

Commit 2338842

Browse files
committed
Skip disabled tests
1 parent 24b7f87 commit 2338842

File tree

3 files changed

+23
-7
lines changed

3 files changed

+23
-7
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -185,11 +185,15 @@ public void run() throws Exception {
185185
for (final var testPath : testPaths) {
186186
try {
187187
final var compilationUnit = javaParser.parse(testPath).getResult().orElseThrow();
188-
final var className = compilationUnit.findFirst(ClassOrInterfaceDeclaration.class)
189-
.map(ClassOrInterfaceDeclaration::getFullyQualifiedName)
190-
.orElseThrow()
191-
.orElseThrow();
192-
classNames.add(className);
188+
final var declaration = compilationUnit.findFirst(ClassOrInterfaceDeclaration.class).orElseThrow();
189+
final var className = declaration.getFullyQualifiedName().orElseThrow();
190+
if (declaration.getAnnotations()
191+
.stream()
192+
.anyMatch(annotationExpr -> "Disabled".equals(annotationExpr.getNameAsString()))) {
193+
LOG.info("Skipping disabled test {}", className);
194+
} else {
195+
classNames.add(className);
196+
}
193197
} catch (final Exception e) {
194198
LOG.error("Failed to parse test class: {}", testPath, e);
195199
exitCodeConsumer.accept(1);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ void setUp() throws Exception {
4343
.resolve("donnerbart")
4444
.resolve("example");
4545
Files.createDirectories(projectFolder);
46+
copyResourceToTarget(projectFolder, "tests/DisabledTest.java", "DisabledTest.java", PERMISSIONS);
4647
copyResourceToTarget(projectFolder, "tests/FastTest.java", "FastTest.java", PERMISSIONS);
4748
copyResourceToTarget(projectFolder, "tests/NoTimingOneTest.java", "NoTimingOneTest.java", PERMISSIONS);
4849
copyResourceToTarget(projectFolder, "tests/NoTimingTwoTest.java", "NoTimingTwoTest.java", PERMISSIONS);
@@ -255,8 +256,7 @@ void run_thirdPartyLibrary() throws Exception {
255256
exitCode::set);
256257
testSplit.run();
257258

258-
assertThat(systemOut.getLines()).singleElement()
259-
.isEqualTo("de.donnerbart.example.ThirdPartyLibraryTest");
259+
assertThat(systemOut.getLines()).singleElement().isEqualTo("de.donnerbart.example.ThirdPartyLibraryTest");
260260
assertThat(exitCode).hasNullValue();
261261
}
262262

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package de.donnerbart.example;
2+
3+
import org.junit.jupiter.api.Disabled;
4+
import org.junit.jupiter.api.Test;
5+
6+
@Disabled("This test should not be split")
7+
class DisabledTest {
8+
9+
@Test
10+
void testDisabled() {
11+
}
12+
}

0 commit comments

Comments
 (0)