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

Improve code coverage through annotations #1789

Open
sarthak-19 opened this issue Jan 11, 2025 · 6 comments
Open

Improve code coverage through annotations #1789

sarthak-19 opened this issue Jan 11, 2025 · 6 comments
Assignees
Labels
Infrastructure Issues for the overall performance plugin infrastructure [Type] Enhancement A suggestion for improvement of an existing feature

Comments

@sarthak-19
Copy link
Contributor

sarthak-19 commented Jan 11, 2025

The current code coverage metrics are as follows :

Image

and can be improved by addressing the following issues:

  1. Ignore Coverage for Non-Critical Code Blocks:

    • Certain ubiquitous code blocks, such as:

      if ( ! defined( 'ABSPATH' ) ) {
          exit;
      } 

      These blocks can be excluded from code coverage by adding // @codeCoverageIgnoreStart and // @codeCoverageIgnoreEnd annotations.

  2. Exclude Plugin Bootstrap Files from Coverage:

    • Files like plugin bootstrap files only include logic that is already tested elsewhere.
    • Evaluate marking uninstall.php as indirectly tested and decide whether similar exclusions are needed for files like hooks.php.
  3. Add Missing @covers Annotations:

    • Ensure all tests have proper @covers annotations to map them to the code they validate. For instance:
      • \Test_OD_URL_Metric::test_constructor is missing a @covers ::get_uuid annotation.
  4. Add Missing Tests:

    • Identify areas of the codebase that are not currently tested and write additional tests to improve overall coverage.

These changes aim to focus coverage metrics on critical functionality and ensure more accurate and meaningful reports, improving code quality and maintainability.

cc : @westonruter

@github-project-automation github-project-automation bot moved this to Not Started/Backlog 📆 in WP Performance 2024 Jan 11, 2025
@westonruter westonruter added the [Type] Enhancement A suggestion for improvement of an existing feature label Jan 12, 2025
@westonruter westonruter moved this from Not Started/Backlog 📆 to To Do 🔧 in WP Performance 2024 Jan 13, 2025
@swissspidy swissspidy changed the title Improve Low Code Coverage by Ignoring Non-Critical Code and Adding Missing @cover Annotation Improve code coverage through annotations Jan 14, 2025
@swissspidy swissspidy added the Infrastructure Issues for the overall performance plugin infrastructure label Jan 14, 2025
@westonruter
Copy link
Member

Ignore Coverage for Non-Critical Code Blocks:

See #1815

@westonruter
Copy link
Member

Work underway for Optimization Detective in #1817.

@westonruter
Copy link
Member

  • decide whether similar exclusions are needed for files like hooks.php

See #1817 (comment). We could avoid adding coverage-exclusion comments if we ensure that no plugins define any functions in their hooks.php. If they simply call add_action() and add_filter() in hooks.php, then coverage could be obtained by adding a test that removes all actions and filters, does a require on the hooks.php file, and then asserts that the actions and filters are present.

@sarthak-19
Copy link
Contributor Author

Work underway for Dominant Color Images in #1837

@westonruter westonruter moved this from To Do 🔧 to In Progress 🚧 in WP Performance 2024 Jan 30, 2025
@sarthak-19
Copy link
Contributor Author

sarthak-19 commented Feb 3, 2025

Work underway for Speculation-Rules Plugin for coverage improvements. #1845

@sarthak-19
Copy link
Contributor Author

Work underway for Web-Worker-Offloading plugin

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Infrastructure Issues for the overall performance plugin infrastructure [Type] Enhancement A suggestion for improvement of an existing feature
Projects
Status: In Progress 🚧
Development

No branches or pull requests

3 participants