diff --git a/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/BuildJobExecutionService.java b/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/BuildJobExecutionService.java index 38305201afa3..36d7d9e44f81 100644 --- a/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/BuildJobExecutionService.java +++ b/src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/BuildJobExecutionService.java @@ -344,7 +344,14 @@ private BuildResult parseTestResults(TarArchiveInputStream testResultsTarInputSt else { // ugly workaround because in swift result files \n\t breaks the parsing var testResultFileString = xmlString.replace("\n\t", ""); - processTestResultFile(testResultFileString, failedTests, successfulTests); + if (!testResultFileString.isBlank()) { + processTestResultFile(testResultFileString, failedTests, successfulTests); + } + else { + String msg = "The file " + fileName + " does not contain any testcases."; + buildLogsMap.appendBuildLogEntry(buildJobId, msg); + log.warn(msg); + } } } catch (IllegalStateException e) { diff --git a/src/test/java/de/tum/in/www1/artemis/AbstractSpringIntegrationLocalCILocalVCTest.java b/src/test/java/de/tum/in/www1/artemis/AbstractSpringIntegrationLocalCILocalVCTest.java index 048627fe6b3c..e6a814bf82ec 100644 --- a/src/test/java/de/tum/in/www1/artemis/AbstractSpringIntegrationLocalCILocalVCTest.java +++ b/src/test/java/de/tum/in/www1/artemis/AbstractSpringIntegrationLocalCILocalVCTest.java @@ -140,6 +140,8 @@ public abstract class AbstractSpringIntegrationLocalCILocalVCTest extends Abstra protected static final Path OLD_REPORT_FORMAT_TEST_RESULTS_PATH = GRADLE_TEST_RESULTS_PATH.resolve("old-report-format"); + protected static final Path EMPTY_TEST_RESULTS_PATH = GRADLE_TEST_RESULTS_PATH.resolve("empty"); + private static final Path SCA_REPORTS_PATH = Path.of("src", "test", "resources", "test-data", "static-code-analysis", "reports"); protected static final Path SPOTBUGS_RESULTS_PATH = SCA_REPORTS_PATH.resolve("spotbugsXml.xml"); diff --git a/src/test/java/de/tum/in/www1/artemis/localvcci/LocalCIIntegrationTest.java b/src/test/java/de/tum/in/www1/artemis/localvcci/LocalCIIntegrationTest.java index 15b47a2a8000..c1c736b89473 100644 --- a/src/test/java/de/tum/in/www1/artemis/localvcci/LocalCIIntegrationTest.java +++ b/src/test/java/de/tum/in/www1/artemis/localvcci/LocalCIIntegrationTest.java @@ -379,6 +379,25 @@ void testStaticCodeAnalysis() throws IOException { localVCLocalCITestService.testLatestSubmission(studentParticipation.getId(), commitHash, 1, false, true, 15, null); } + @Test + @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER") + void testEmptyResultFile() throws Exception { + ProgrammingExerciseStudentParticipation studentParticipation = localVCLocalCITestService.createParticipation(programmingExercise, student1Login); + + localVCLocalCITestService.mockTestResults(dockerClient, EMPTY_TEST_RESULTS_PATH, LOCALCI_WORKING_DIRECTORY + LOCALCI_RESULTS_DIRECTORY); + localVCServletService.processNewPush(commitHash, studentAssignmentRepository.originGit.getRepository()); + localVCLocalCITestService.testLatestSubmission(studentParticipation.getId(), commitHash, 0, true); + + studentParticipation = programmingExerciseStudentParticipationRepository + .findByIdWithLatestResultAndFeedbacksAndRelatedSubmissions(studentParticipation.getId(), ZonedDateTime.now()).orElseThrow(); + var result = studentParticipation.getResults().iterator().next(); + + var buildLogs = buildLogEntryService.getLatestBuildLogs((ProgrammingSubmission) result.getSubmission()); + + assertThat(buildLogs).isNotEmpty().anyMatch(log -> log.getLog().equals("The file results.xml does not contain any testcases.\n")) + .noneMatch(log -> log.getLog().contains("Exception")); + } + @Test @WithMockUser(username = TEST_PREFIX + "student1", roles = "USER") void testBuildLogs() throws IOException { diff --git a/src/test/resources/test-data/test-results/java-gradle/empty/results.xml b/src/test/resources/test-data/test-results/java-gradle/empty/results.xml new file mode 100644 index 000000000000..e69de29bb2d1