diff --git a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java index 5e2672e4b426..50c3c5925f97 100644 --- a/src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java +++ b/src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java @@ -33,22 +33,8 @@ public static void processTestResultFile(String testResultFileString, List element - // And parse the inner test suites - TestSuites suites = mapper.readValue(testResultFileString, TestSuites.class); - if (suites.testsuites() == null) { - return; - } - - for (TestSuite suite : suites.testsuites()) { - processTestSuite(suite, failedTests, successfulTests); - } - } + // A toplevel element is parsed like a + processTestSuite(testSuite, failedTests, successfulTests); } private static void processTestSuite(TestSuite testSuite, List failedTests, List successfulTests) { @@ -64,17 +50,19 @@ private static void processTestSuite(TestSuite testSuite, List testsuites) { + for (TestSuite suite : testSuite.testSuites()) { + processTestSuite(suite, failedTests, successfulTests); + } } @JsonIgnoreProperties(ignoreUnknown = true) - record TestSuite(@JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlProperty(localName = "testcase") List testCases) { + record TestSuite(@JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlProperty(localName = "testcase") List testCases, + @JacksonXmlElementWrapper(useWrapping = false) @JacksonXmlProperty(localName = "testsuite") List testSuites) { TestSuite { testCases = Objects.requireNonNullElse(testCases, Collections.emptyList()); + testSuites = Objects.requireNonNullElse(testSuites, Collections.emptyList()); } } diff --git a/src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java b/src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java index 3af5e6b64a69..f228d0223f9d 100644 --- a/src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java +++ b/src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java @@ -208,4 +208,42 @@ void testEmptyTestMessage() throws IOException { assertThat(test.getName()).isEqualTo("mwe-name"); assertThat(test.getTestMessages()).hasSize(1).contains(""); } + + @Test + void testNestedTestsuite() throws IOException { + String input = """ + + + + + + + + + + + + + + + + + + + + + + + + + + """; + + TestResultXmlParser.processTestResultFile(input, failedTests, successfulTests); + assertThat(successfulTests).hasSize(12).extracting(BuildResult.LocalCITestJobDTO::getName).containsExactlyInAnyOrder("Testing filtering in A", "Testing mapping in A", + "Testing filtering in B", "Testing mapping in B", "Testing filtering in C", "Testing mapping in C", "Testing A against sample solution", + "Testing B against sample solution", "Testing C against sample solution", "Testing selectAndReflectA (0,0) []", "Testing selectAndReflectB (0,1) [(0,0)]", + "Testing selectAndReflectC (0,1) [(-1,-1)]"); + assertThat(failedTests).isEmpty(); + } }