Skip to content

Commit 5727216

Browse files
committed
Skip malformed JUnit reports instead of failing
1 parent 0b6f812 commit 5727216

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

‎src/main/java/de/donnerbart/split/TestLoader.java‎

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package de.donnerbart.split;
22

3+
import com.fasterxml.jackson.core.JacksonException;
34
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
45
import com.github.javaparser.JavaParser;
56
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
@@ -75,7 +76,13 @@ public TestLoader(
7576
var slowestTest = new TestCase("", Double.MIN_VALUE);
7677
final var xmlMapper = new XmlMapper();
7778
for (final var junitPath : junitPaths) {
78-
final var testSuite = xmlMapper.readValue(junitPath.toFile(), TestSuite.class);
79+
final TestSuite testSuite;
80+
try {
81+
testSuite = xmlMapper.readValue(junitPath.toFile(), TestSuite.class);
82+
} catch (final JacksonException e) {
83+
LOG.warn("Skipping malformed JUnit report {}: {}", junitPath, e.getOriginalMessage());
84+
continue;
85+
}
7986
final var testCase = new TestCase(testSuite.getName(), testSuite.getTime());
8087
if (classNames.contains(testCase.name())) {
8188
if (testCases.add(testCase)) {

‎src/test/java/de/donnerbart/split/TestLoaderTest.java‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,23 @@ void load_withJUnit_withMaxTestTime() throws Exception {
139139
assertThat(exitCode).hasNullValue();
140140
}
141141

142+
@Test
143+
void load_withJUnit_withMalformedReport() throws Exception {
144+
copyResourceToTarget(tmp.resolve("junit-reports"),
145+
"reports/TEST-de.donnerbart.example.MalformedTest.xml",
146+
"TEST-de.donnerbart.example.NoTimingOneTest.xml",
147+
PERMISSIONS);
148+
149+
final var testCases = loadTests(true, NewTestTimeOption.ZERO);
150+
assertThat(testCases).satisfiesExactlyInAnyOrder( //
151+
testCase -> assertTestCase(testCase, new TestCase("de.donnerbart.example.FastTest", 2.374d)),
152+
testCase -> assertTestCase(testCase, new TestCase("de.donnerbart.example.SlowTest", 12.386d)),
153+
testCase -> assertTestCase(testCase, new TestCase("de.donnerbart.example.SlowestTest", 153.457d)),
154+
testCase -> assertTestCase(testCase, new TestCase("de.donnerbart.example.NoTimingOneTest", 0d)),
155+
testCase -> assertTestCase(testCase, new TestCase("de.donnerbart.example.NoTimingTwoTest", 0d)));
156+
assertThat(exitCode).hasNullValue();
157+
}
158+
142159
@Test
143160
void load_whitespaceClassDefinition() throws Exception {
144161
final var projectFolder =
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<testsuite name="de.donnerbart.example.NoTimingOneTest" tests="1" skipped="0" failures="0" errors="0"
3+
timestamp="2025-01-01T00:00:00" hostname="example" time="99.999">
4+
<properties/>
5+
<testcase name="testMethod()"
6+
classname="de.donnerbart.example.NoTimingOneTest" time="99.999">
7+
<system-out><![CDATA[]]></system-out>
8+
<system-err><![CDATA[]]></system-err>
9+
</testsuite>
10+
tail of a previous report version
11+
</testsuite>

0 commit comments

Comments
 (0)