Skip to content

Development: Improve programming exercise test coverage #10765

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 33 commits into from
May 15, 2025

Conversation

ekayandan
Copy link
Contributor

@ekayandan ekayandan commented Apr 29, 2025

Checklist

General

Server

Motivation and Context

  1. To prevent issues Programming Exercise: Changing the short name while importing breaks tests #7188 and Programming exercises: Build results not available after file import #8562 from happening again
  2. Increase Programming Service code coverage

Description

  1. Added test cases for issues mentioned in motivation
  2. Added test cases to cover missed branches
  3. Reused applicable test cases from ProgrammingExerciseTestService (mainly used in Jenkins integration tests)

Testserver States

You can manage test servers using Helios. Check environment statuses in the environment list. To deploy to a test server, go to the CI/CD page, find your PR or branch, and trigger the deployment.

Code Review

  • Code Review 1
  • Code Review 2

Test Coverage

Class/File Line Coverage Confirmation (assert/expect)
de.tum.cit.aet.artemis.programming.dto 88% ✅ ❌
de.tum.cit.aet.artemis.programming.service 73% ✅ ❌
de.tum.cit.aet.artemis.programming.service.aeolus 93% ✅ ❌
de.tum.cit.aet.artemis.programming.service.localci 84% ✅ ❌
de.tum.cit.aet.artemis.programming.service.localvc 56% ✅ ❌
de.tum.cit.aet.artemis.programming.service.localvc.ssh 85% ✅ ❌

Summary by CodeRabbit

  • Tests
    • Added comprehensive new tests for importing programming exercises from files, handling various error scenarios, and verifying build plan creation.
    • Enhanced test coverage for import validation, including missing or invalid files, forbidden access, and exception handling.
    • Introduced tests for successful imports, title modifications, and asynchronous build plan verification.
    • Added tests for sequential test runs and exam exercise date validations.
  • New Features
    • Introduced a new test service to facilitate programming exercise imports from zip files with customizable modifications.
    • Added utilities to count occurrences of strings within zip archives and directories for content verification.

@github-project-automation github-project-automation bot moved this to Work In Progress in Artemis Development Apr 29, 2025
@github-actions github-actions bot added tests programming Pull requests that affect the corresponding module labels Apr 29, 2025
@ekayandan ekayandan changed the title Reused ProgrammingExerciseTestService cases in ProgrammingExerciseLoc… Development: Improve Programming Exercise test coverage Apr 29, 2025
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed1s 680ms
TestResultTime ⏱
No test annotations available

Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report201 ran196 passed3 skipped2 failed48m 9s 189ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/course/CourseMessages.spec.ts
ts.Course messages › Channel messages › Write/edit/delete message in channel › Student should be able to edit message in channel❌ failure2m 3s 79ms
e2e/exercise/programming/ProgrammingExerciseStaticCodeAnalysis.spec.ts
ts.Static code analysis tests › Configures SCA grading and makes a successful submission with SCA errors❌ failure1m 39s 465ms

Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report201 ran195 passed3 skipped3 failed46m 34s 266ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/course/CourseMessages.spec.ts
ts.Course messages › Channel messages › Write/edit/delete message in channel › Student should be able to edit message in channel❌ failure2m 3s 531ms
e2e/exercise/quiz-exercise/QuizExerciseManagement.spec.ts
ts.Quiz Exercise Management › Quiz Exercise Creation › Creates a Quiz with Drag and Drop❌ failure2m 1s 968ms
e2e/exercise/quiz-exercise/QuizExerciseParticipation.spec.ts
ts.Quiz Exercise Participation › DnD Quiz participation › Student can participate in DnD Quiz❌ failure2m 3s 23ms

Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report201 ran194 passed3 skipped4 failed53m 15s 693ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/course/CourseMessages.spec.ts
ts.Course messages › Channel messages › Write/edit/delete message in channel › Student should be able to edit message in channel❌ failure2m 2s 970ms
e2e/exercise/quiz-exercise/QuizExerciseManagement.spec.ts
ts.Quiz Exercise Management › Quiz Exercise Creation › Creates a Quiz with Drag and Drop❌ failure2m 2s 473ms
e2e/exercise/quiz-exercise/QuizExerciseParticipation.spec.ts
ts.Quiz Exercise Participation › DnD Quiz participation › Student can participate in DnD Quiz❌ failure2m 3s 72ms
e2e/exercise/programming/ProgrammingExerciseStaticCodeAnalysis.spec.ts
ts.Static code analysis tests › Configures SCA grading and makes a successful submission with SCA errors❌ failure1m 46s 196ms

Copy link

github-actions bot commented May 5, 2025

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed1s 586ms
TestResultTime ⏱
No test annotations available

Copy link

github-actions bot commented May 5, 2025

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report201 ran194 passed3 skipped4 failed55m 32s 309ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/course/CourseMessages.spec.ts
ts.Course messages › Channel messages › Write/edit/delete message in channel › Student should be able to edit message in channel❌ failure2m 3s 93ms
e2e/exercise/quiz-exercise/QuizExerciseManagement.spec.ts
ts.Quiz Exercise Management › Quiz Exercise Creation › Creates a Quiz with Drag and Drop❌ failure2m 2s 81ms
e2e/exercise/quiz-exercise/QuizExerciseParticipation.spec.ts
ts.Quiz Exercise Participation › DnD Quiz participation › Student can participate in DnD Quiz❌ failure2m 3s 211ms
e2e/exercise/programming/ProgrammingExerciseStaticCodeAnalysis.spec.ts
ts.Static code analysis tests › Configures SCA grading and makes a successful submission with SCA errors❌ failure1m 48s 777ms

Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report201 ran197 passed3 skipped1 failed53m 39s 79ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/exercise/programming/ProgrammingExerciseStaticCodeAnalysis.spec.ts
ts.Static code analysis tests › Configures SCA grading and makes a successful submission with SCA errors❌ failure1m 54s 422ms

Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ✅SkippedFailedTime ⏱
End-to-End (E2E) Test Report1 ran1 passed0 skipped0 failed1s 588ms
TestResultTime ⏱
No test annotations available

Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report201 ran197 passed3 skipped1 failed55m 46s 209ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/exercise/programming/ProgrammingExerciseStaticCodeAnalysis.spec.ts
ts.Static code analysis tests › Configures SCA grading and makes a successful submission with SCA errors❌ failure1m 48s 680ms

@ekayandan ekayandan requested a review from krusche May 14, 2025 10:21
marlonnienaber
marlonnienaber previously approved these changes May 14, 2025
Copy link
Contributor

@marlonnienaber marlonnienaber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks good

Copy link
Contributor

@florian-glombik florian-glombik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code

I left some suggestions for future PRs.

The actual testing code is quite clean and well understandable. For me the Code in ProgrammingExerciseImportTestService is rather hard to understand, I think that the abbreviations and too short variable names make it harder to understand than it would need to be - but this might also be an opinionated topic

Another thing, please link issues properly to PRs https://docs.github.com/en/get-started/writing-on-github/working-with-advanced-formatting/using-keywords-in-issues-and-pull-requests. Bought of the linked issues are still open but should be closed, shouldn't they (I did that manually just now)?

If they are linked properly that happens automatically once the PR is merged

Copy link
Contributor

@florian-glombik florian-glombik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mmh, unfortunately one tests seems to fail in the pipeline? - ProgrammingExerciseLocalVCLocalCIIntegrationTest importFromFile_verifyBuildPlansCreated()

https://bamboo.ase.in.tum.de/browse/ARTEMIS-TESTS8121-JAVATEST-28

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java (1)

366-399: Good implementation of import test with title modification verification.

The test properly verifies that title changes propagate to all repository files by comparing occurrences in extracted directories and zip files. Consider adding the assertion that newTitleCount != 0 to ensure the test is valid when no occurrences are found.

        assertThat(newTitleCount).isEqualTo(programmingExerciseImportTestService.countOccurrencesInZip(importResult.resource(), oldTitle));
+       assertThat(newTitleCount).isGreaterThan(0);
        assertThat(oldTitleCount).isZero();
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 7180112 and b46b3cb.

📒 Files selected for processing (1)
  • src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java (7 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`src/test/java/**/*.java`: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_...

src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

  • src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Build and Push Docker Image / Build Docker Image for ls1intum/artemis
  • GitHub Check: Build and Push Docker Image / Build Docker Image for ls1intum/artemis
  • GitHub Check: Build .war artifact
  • GitHub Check: server-style
  • GitHub Check: client-style
  • GitHub Check: client-tests
  • GitHub Check: server-tests
  • GitHub Check: Analyse
🔇 Additional comments (9)
src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java (9)

85-89: Good refactoring using the autowired test services.

The integration of ProgrammingExerciseTestService and ProgrammingExerciseImportTestService follows the suggested utility/service pattern from previous review comments, promoting code reuse and better test organization.


142-144: Good delegation to test service for setup.

The setup has been properly refactored to delegate user initialization and environment setup to the test service, following the previous recommendation to factor out setup logic into service classes.


158-158: Proper test cleanup using service.

The tearDown method correctly uses the test service for cleanup operations. This ensures consistent resource management across tests.


311-339: Well-organized delegation of import error tests.

These test methods effectively delegate to the test service to verify various error handling scenarios for importing programming exercises. This pattern improves maintainability by centralizing test logic.


341-345: Good CI failure test.

This test correctly validates the system's behavior when failing to create a project in the CI environment, which helps prevent issue regression.


347-352: Excellent use of parameterized testing for date validation.

The @ParameterizedTest with ArgumentsSource follows JUnit 5 best practices for testing multiple input combinations, which is ideal for date validation scenarios.


401-414: Clean implementation of basic import test.

This test verifies the basic functionality of importing a valid exercise without modifications, focusing on core verification points like exercise properties and course association.


416-461: Comprehensive build plan verification test.

This test effectively mocks Docker interactions to verify that build plans are properly created after import. Good practice using try-catch with a detailed error message to help with troubleshooting.


463-491: Good test for sequential test runs feature.

The test properly verifies that exercises can be created with sequential test runs enabled. It follows the same pattern as other creation tests while focusing on the specific feature being tested.

coderabbitai[bot]
coderabbitai bot previously approved these changes May 14, 2025
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report201 ran197 passed3 skipped1 failed59m 45s 241ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/exercise/programming/ProgrammingExerciseStaticCodeAnalysis.spec.ts
ts.Static code analysis tests › Configures SCA grading and makes a successful submission with SCA errors❌ failure1m 53s 806ms

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

♻️ Duplicate comments (1)
src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java (1)

161-161: Consider addressing the disabled test

The test on line 161 is still disabled. According to previous review comments, there was an attempt to fix it.

Could you provide an update on the status of this test? If it's intentionally disabled, consider adding a comment explaining why.

🧹 Nitpick comments (2)
src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java (2)

370-403: Well-structured test for title replacement during import

This test effectively verifies that when changing a title during import, the new title properly replaces the old one in all repository files. The test covers a specific use case mentioned in issue #7188.

However, you could strengthen the assertion on line 401 by adding a check that newTitleCount is not zero:

- assertThat(newTitleCount).isEqualTo(programmingExerciseImportTestService.countOccurrencesInZip(importResult.resource(), oldTitle));
+ assertThat(newTitleCount).isEqualTo(programmingExerciseImportTestService.countOccurrencesInZip(importResult.resource(), oldTitle))
+                          .isGreaterThan(0);

This would guard against the case where both counts are zero, which would pass the current test but indicate a potential issue with the counting mechanism.


451-468: Improve exception handling approach

The current try-catch block catches all exceptions and wraps them in an AssertionError, which can obscure the original exception details.

Consider replacing the generic Exception with more specific exceptions or removing the try-catch block altogether:

- try {
    // Refresh the exercise to get latest participation data
    ProgrammingExercise refreshedExercise = programmingExerciseRepository.findWithAllParticipationsAndBuildConfigById(importedExercise.getId()).orElseThrow();

    // Verify template build plan
    TemplateProgrammingExerciseParticipation templateParticipation = templateProgrammingExerciseParticipationRepository
            .findByProgrammingExerciseId(refreshedExercise.getId()).orElseThrow();

    localVCLocalCITestService.testLatestSubmission(templateParticipation.getId(), null, 0, false, 30);

    // Verify solution build plan
    SolutionProgrammingExerciseParticipation solutionParticipation = solutionProgrammingExerciseParticipationRepository
            .findByProgrammingExerciseId(refreshedExercise.getId()).orElseThrow();

    localVCLocalCITestService.testLatestSubmission(solutionParticipation.getId(), null, 13, false, 30);
- }
- catch (Exception e) {
-     throw new AssertionError("Failed to verify build plans", e);
- }

This will allow JUnit to handle the exceptions directly and provide more detailed failure information.

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b46b3cb and 8186130.

📒 Files selected for processing (2)
  • src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java (7 hunks)
  • src/test/java/de/tum/cit/aet/artemis/programming/util/ProgrammingExerciseImportTestService.java (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/java/de/tum/cit/aet/artemis/programming/util/ProgrammingExerciseImportTestService.java
🧰 Additional context used
📓 Path-based instructions (1)
`src/test/java/**/*.java`: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_...

src/test/java/**/*.java: test_naming: descriptive; test_size: small_specific; fixed_data: true; junit5_features: true; assert_use: assertThat; assert_specificity: true; archunit_use: enforce_package_rules; db_query_count_tests: track_performance; util_service_factory_pattern: true; avoid_db_access: true; mock_strategy: static_mocks; context_restart_minimize: true

  • src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java
🧬 Code Graph Analysis (1)
src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java (1)
src/test/java/de/tum/cit/aet/artemis/programming/util/ProgrammingExerciseFactory.java (1)
  • ProgrammingExerciseFactory (46-472)
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Build and Push Docker Image / Build Docker Image for ls1intum/artemis
  • GitHub Check: Build .war artifact
  • GitHub Check: Build and Push Docker Image / Build Docker Image for ls1intum/artemis
  • GitHub Check: client-tests
  • GitHub Check: server-tests
  • GitHub Check: client-style
  • GitHub Check: server-style
  • GitHub Check: Analyse
🔇 Additional comments (9)
src/test/java/de/tum/cit/aet/artemis/programming/icl/ProgrammingExerciseLocalVCLocalCIIntegrationTest.java (9)

85-89: Good refactoring using autowired test services

Using dedicated test services with dependency injection helps improve code organization and reusability. This follows the util_service_factory_pattern guideline.


143-144: Good delegation of test setup to the service

This delegation properly separates test setup logic into a reusable component, making the test class more maintainable.


158-158: Good teardown delegation

Delegating the teardown logic to the test service ensures proper cleanup between tests, maintaining test isolation.


311-315: Good test modularization for import error cases

Delegating test implementations to the ProgrammingExerciseTestService promotes code reuse and improves readability. This pattern is consistently applied across multiple test methods.


347-352: Good use of parameterized tests

Using parameterized tests with an argument provider is an excellent practice for testing multiple invalid date configurations without code duplication. This follows the junit5_features guideline.


366-369: Good documentation linking to GitHub issue

The JavaDoc comment linking to GitHub issue #7188 provides helpful context about which regression this test is preventing.


420-423: Good documentation linking to GitHub issue

The JavaDoc comment linking to GitHub issue #8562 provides helpful context about which regression this test is preventing.


424-469: Comprehensive test for build plan creation verification

This test thoroughly verifies that build plans are correctly created after an import operation, including mocking Docker interactions and verifying both template and solution build plans.


471-499: Good test for sequential test runs

This test verifies the creation of a programming exercise with sequential test runs enabled, which improves test coverage as mentioned in the PR objectives.

Copy link
Contributor

@florian-glombik florian-glombik left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code, Thanks for the changes :)

@ekayandan ekayandan requested a review from marlonnienaber May 14, 2025 14:40
Copy link

End-to-End (E2E) Test Results Summary

TestsPassed ☑️Skipped ⚠️Failed ❌️Time ⏱
End-to-End (E2E) Test Report201 ran197 passed3 skipped1 failed53m 56s 539ms
TestResultTime ⏱
End-to-End (E2E) Test Report
e2e/exercise/programming/ProgrammingExerciseStaticCodeAnalysis.spec.ts
ts.Static code analysis tests › Configures SCA grading and makes a successful submission with SCA errors❌ failure1m 48s 438ms

Copy link
Contributor

@marlonnienaber marlonnienaber left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reapprove code

Copy link
Contributor

@jfr2102 jfr2102 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reapproving test code

Copy link

End-to-End (E2E) Test Results Summary

@krusche krusche merged commit a1a8a8c into develop May 15, 2025
30 of 33 checks passed
@krusche krusche deleted the chore/improve-programming-exercise-tests branch May 15, 2025 12:23
@github-project-automation github-project-automation bot moved this from Ready For Review to Merged in Artemis Development May 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
programming Pull requests that affect the corresponding module ready for review ready to merge tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

10 participants