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

[dotnet] Correct assertion of struct type in internal tests #14878

Merged
merged 2 commits into from
Dec 19, 2024

Conversation

RenderMichael
Copy link
Contributor

@RenderMichael RenderMichael commented Dec 9, 2024

User description

Thanks for contributing to Selenium!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Finishes future-proofing for a potential NUnit 4 upgrade. With this, I upgraded locally to NUnit 4.x and the tests ran and passed.

Motivation and Context

Fixes #14852

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

enhancement, tests


Description

  • Updated NUnit assertions in DevToolsProfilerTest.cs to ensure StartTime, EndTime, and TimeDeltas are non-zero, enhancing test robustness.
  • Improved message formatting in DevToolsTestFixture.cs by using string interpolation for Assert.Ignore.

Changes walkthrough 📝

Relevant files
Enhancement
DevToolsProfilerTest.cs
Update NUnit assertions for profiler validation                   

dotnet/test/common/DevTools/DevToolsProfilerTest.cs

  • Changed assertions for StartTime and EndTime to check for non-zero
    values.
  • Updated assertion for TimeDeltas to check for non-zero values.
  • +3/-3     
    DevToolsTestFixture.cs
    Use string interpolation for ignore message                           

    dotnet/test/common/DevTools/DevToolsTestFixture.cs

  • Modified Assert.Ignore message formatting to use string interpolation.

  • +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 9, 2024

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 1 🔵⚪⚪⚪⚪
    🧪 PR contains tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Test Coverage
    The test now checks for non-zero values instead of non-null. Verify this is the correct validation for profiler timing data.

    Copy link
    Contributor

    qodo-merge-pro bot commented Dec 9, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    General
    Remove unreachable code that follows a test assertion that always throws an exception

    The return statement after Assert.Ignore is unreachable code since Assert.Ignore
    throws an exception. Remove the redundant return statement.

    dotnet/test/common/DevTools/DevToolsTestFixture.cs [42-43]

     Assert.Ignore($"{EnvironmentManager.Instance.Browser} does not support Chrome DevTools Protocol");
    -return;
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    Why: The suggestion correctly identifies that the return statement after Assert.Ignore is redundant since Assert.Ignore always throws an exception. Removing it improves code clarity and eliminates dead code.

    7
    Simplify collection validation by using LINQ instead of explicit iteration

    The foreach loop for TimeDeltas contains only an assertion without any other logic.
    Consider using LINQ's All() method for a more concise and idiomatic check.

    dotnet/test/common/DevTools/DevToolsProfilerTest.cs [137-140]

    -foreach (var delta in profiler.TimeDeltas)
    -{
    -    Assert.That(delta, Is.Not.Zero);
    -}
    +Assert.That(profiler.TimeDeltas.All(delta => delta != 0), Is.True, "All time deltas should be non-zero");
    • Apply this suggestion
    Suggestion importance[1-10]: 5

    Why: The suggestion proposes a more concise LINQ-based approach which is idiomatic in C#. While functionally equivalent, it's primarily a stylistic improvement that makes the code more readable but doesn't affect functionality.

    5

    💡 Need additional feedback ? start a PR chat

    @nvborisenko nvborisenko changed the title [dotnet] Complete NUnit 4 future-proofing [dotnet] Correct assertion of struct type in internal tests Dec 19, 2024
    @nvborisenko
    Copy link
    Member

    Thank you @RenderMichael !

    @nvborisenko nvborisenko merged commit 4f25f67 into SeleniumHQ:trunk Dec 19, 2024
    1 check passed
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    [dotnet] Future-proof for NUnit 4.x upgrade
    2 participants