Skip to content
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

Programming exercises: Fix test case parsing of nested test suite elements #9490

Merged
merged 2 commits into from
Oct 20, 2024

Conversation

magaupp
Copy link
Contributor

@magaupp magaupp commented Oct 15, 2024

Checklist

General

Server

Changes affecting Programming Exercises

  • High priority: I tested all changes and their related features with all corresponding user types on a test server configured with the integrated lifecycle setup (LocalVC and LocalCI).
  • I tested all changes and their related features with all corresponding user types on a local server configured with LocalVC and Jenkins.

Motivation and Context

The JUnit XML format allows <testcase> elements to contain other <testcase> elements. The current parser is not able to handle this.
The Haskell template, for example, produces such files and fails on LocalCI.

Description

The handling of <testcases> and <testcase> elements can be generalized, such that both elements are handled the same.
This reduces special cases and simplifies the code as well.

Fixes #9159.

Steps for Testing

Prerequisites:

  • 1 Instructor
  1. Create an Haskell exercise on a LocalCI server
  2. Validate that the build plans on the template and solution repos finish successfully

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Test Coverage

Class/File Line Coverage Confirmation (assert/expect)
TestResultXmlParser 96%

Summary by CodeRabbit

  • New Features

    • Enhanced parsing logic for test result files, now supporting nested test suites.
    • Improved handling of both single and multiple test suites for streamlined processing.
  • Bug Fixes

    • Corrected the counting of successful tests in nested test suite scenarios.
  • Tests

    • Added a new test case to validate the parsing of XML input with nested test suites.

@magaupp magaupp requested a review from a team as a code owner October 15, 2024 10:22
@github-actions github-actions bot added tests server Pull requests that update Java code. (Added Automatically!) buildagent Pull requests that affect the corresponding module labels Oct 15, 2024
Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

The pull request introduces significant modifications to the TestResultXmlParser class, specifically in the processTestResultFile method, which now processes test results more directly by removing unnecessary conditional checks. The TestSuite record is updated to include a new field for nested test suites, facilitating recursive processing. Additionally, a new test method is added to the TestResultXmlParserTest class to validate the handling of nested test suites, ensuring comprehensive test coverage.

Changes

File Change Summary
src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java Updated processTestResultFile method to streamline parsing logic and added testSuites field to TestSuite record.
src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java Added testNestedTestsuite method to test nested XML structures in processTestResultFile.

Assessment against linked issues

Objective Addressed Explanation
Haskell Template functionality (issue #9159) The changes do not address the Haskell template issue.

Possibly related PRs

Suggested labels

ready for review, bugfix, small, atlas

Suggested reviewers

  • krusche
  • pzdr7
  • SimonEntholzer

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 3

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between a5167be and 4144f86.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java (2 hunks)
  • src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java (1)

Pattern 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

📓 Learnings (3)
📓 Common learnings
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:42.972Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:48.768Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java (2)
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:42.972Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:48.768Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java (2)
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:42.972Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:48.768Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
🔇 Additional comments (2)
src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java (2)

36-37: LGTM

The added comment improves code clarity by explaining that a top-level <testsuites> element is parsed like a <testsuite>. The recursive processing enhances the parser's ability to handle different XML structures.


60-61: LGTM

The addition of the testSuites field to the TestSuite record allows effective parsing of nested test suites. The use of annotations ensures proper deserialization of the XML elements.

Copy link

coderabbitai bot commented Oct 15, 2024

Walkthrough

The changes in this pull request focus on the TestResultXmlParser class, specifically in the processTestResultFile method and the TestSuite record. The method has been simplified to directly process the testSuite object without prior conditional checks. Additionally, the TestSuite record has been modified to include a new field for nested test suites. Correspondingly, the TestResultXmlParserTest class has been updated to include a new test method that verifies the parsing of XML with nested test suites.

Changes

File Path Change Summary
src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java - Updated processTestResultFile method to simplify logic by removing conditional checks.
- Modified TestSuite record to include a list of nested TestSuite objects.
src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java - Added new test method testNestedTestsuite to verify parsing of nested <testsuite> elements in XML input.

Possibly related PRs

Suggested labels

ready for review, programming

Suggested reviewers

  • BBesrour
  • krusche
  • pzdr7
  • SimonEntholzer

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between a5167be and 4144f86.

📒 Files selected for processing (2)
  • src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java (2 hunks)
  • src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java (1)

Pattern src/main/java/**/*.java: naming:CamelCase; principles:{single_responsibility,small_methods,no_duplication}; db:{perf_queries,datetime_not_timestamp}; rest:{stateless,singleton,delegate_logic,http_only,minimal_dtos}; dtos:{java_records,no_entities,min_data,single_resp}; di:constructor_injection; kiss:simple_code; file_handling:os_indep_paths; practices:{least_access,avoid_transactions,code_reuse,static_member_ref,prefer_primitives}; sql:{param_annotation,uppercase,avoid_subqueries};java:avoid_star_imports

src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java (1)

Pattern 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

📓 Learnings (3)
📓 Common learnings
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:42.972Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:48.768Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java (2)
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:42.972Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:48.768Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java (2)
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:42.972Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:48.768Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
🔇 Additional comments (4)
src/main/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParser.java (4)

36-37: LGTM: Simplified processing of test suites

The changes to directly process the testSuite object streamline the method and enhance readability.


54-56: LGTM: Added processing of nested test suites

The addition of the loop to process nested test suites ensures that all nested test cases are properly handled.


60-61: LGTM: Updated TestSuite record to include nested test suites

The inclusion of the testSuites field in the TestSuite record, along with the appropriate Jackson annotations, allows for correct parsing of nested <testsuite> elements.


65-65: LGTM: Initialized testSuites to an empty list if null

By using Objects.requireNonNullElse, testSuites is set to an empty list when null, preventing potential NullPointerException during iteration.

Copy link

@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: 1

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: ASSERTIVE

📥 Commits

Files that changed from the base of the PR and between 4144f86 and a444db5.

📒 Files selected for processing (1)
  • src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java (1)

Pattern 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

📓 Learnings (2)
📓 Common learnings
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:42.972Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:48.768Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
src/test/java/de/tum/cit/aet/artemis/buildagent/service/TestResultXmlParserTest.java (2)
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:42.972Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.
Learnt from: Strohgelaender
PR: ls1intum/Artemis#8677
File: src/main/java/de/tum/in/www1/artemis/service/connectors/localci/buildagent/TestResultXmlParser.java:0-0
Timestamp: 2024-10-08T15:35:48.768Z
Learning: The `TestSuite` constructor in `TestResultXmlParser.java` was improved by using `Objects.requireNonNullElse` to handle null values concisely.

Copy link
Contributor

@Strohgelaender Strohgelaender 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 to me

Copy link

@sachmii sachmii left a comment

Choose a reason for hiding this comment

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

Tested on TS2, works fine and the bug reported in issue #9159 does not occur, therefore fixing it.

Copy link
Contributor

@ole-ve ole-ve 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

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

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

tested on TS4. Works great!
image

Copy link
Member

@krusche krusche 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 👍

@krusche krusche added the maintainer-approved The feature maintainer has approved the PR label Oct 19, 2024
@krusche krusche changed the title Programming exercises: Fix JUnit XML parsing of nested testsuite elements Programming exercises: Fix test case parsing of nested test suite elements Oct 20, 2024
@krusche krusche merged commit 96e53d4 into develop Oct 20, 2024
85 of 89 checks passed
@krusche krusche deleted the chore/programming-exercises/fix-nested-testcase branch October 20, 2024 07:27
SimonEntholzer pushed a commit that referenced this pull request Oct 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
buildagent Pull requests that affect the corresponding module maintainer-approved The feature maintainer has approved the PR ready to merge server Pull requests that update Java code. (Added Automatically!) tests
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Haskell Programming Template doesn't work
6 participants