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

refactor(metrics): unit tests for Metrics are written to follow similar convention as Logger/Tracer #1414

Merged
merged 98 commits into from
Apr 24, 2023

Conversation

arnabrahman
Copy link
Contributor

@arnabrahman arnabrahman commented Apr 20, 2023

Description of your changes

Metrics unit tests were not following the same convention as Logger/Tracer package. In Logger/Tracer tests, only public functions are unit tested. But for Metrics, unit tests are written per feature/behavior.

This PR updates the tests to match the same convention as Logger/Tracer package. Only public methods are tested, following the recommendations here: Best Practices

100% test coverage is maintained. Some additional housekeeping is implemented, constants & helpers are introduced for better code maintainability.

I've removed the previous feature tests because in my understanding leaving them will create further confusion about the testing patterns. I can add them again if maintainers feel the current sets of tests in this PR are inadequate.

How to verify this change

All the tests will run successfully along with 100% test coverage.

Related issues, RFCs

Issue number: #163

Checklist

  • My changes meet the tenets criteria
  • I have performed a self-review of my own code
  • I have commented my code where necessary, particularly in areas that should be flagged with a TODO, or hard-to-understand areas
  • I have made corresponding changes to the documentation
  • I have made corresponding changes to the examples
  • My changes generate no new warnings
  • The code coverage hasn't decreased
  • I have added tests that prove my change is effective and works
  • New and existing unit tests pass locally and in Github Actions
  • Any dependent changes have been merged and published
  • The PR title follows the conventional commit semantics

Breaking change checklist

Is it a breaking change?: NO

  • I have documented the migration process
  • I have added, implemented necessary warnings (if it can live side by side)

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

@pull-request-size pull-request-size bot added the size/XXL PRs with 1K+ LOC, largely documentation related label Apr 20, 2023
@arnabrahman arnabrahman marked this pull request as ready for review April 20, 2023 09:21
@dreamorosi
Copy link
Contributor

Hi @arnabrahman thank you so much for opening this PR!

Given the size, please allow us some time to go through it and review it.

I'll get back to you here with comments as I review it.

@dreamorosi dreamorosi self-requested a review April 20, 2023 10:13
@github-actions github-actions bot added the feature PRs that introduce new features or minor changes label Apr 20, 2023
@dreamorosi dreamorosi self-requested a review April 21, 2023 07:04
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

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

I've done a first review and things are looking good!

I have left one comment about the helper function, that I think we could drop.

Now I'm going to focus on reviewing the actual test cases and see if all the previous ones are covered.

This helper will be removed/deprecated from all utilities(i.e. createLogger) in the next major release. So, avoiding it is logical.
Removing createMetrics helper function and related tests impacts 100% code coverage. So, instead createMetrics tests can be used as constructor method tests for Metrics class. As a result 100% test coverage will not be impacted.
@dreamorosi dreamorosi self-requested a review April 24, 2023 16:49
Copy link
Contributor

@dreamorosi dreamorosi left a comment

Choose a reason for hiding this comment

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

Hi @arnabrahman thank you so much for the work you've done here.

I really appreciate the effort and dedication you've put into improving the project.

@dreamorosi dreamorosi linked an issue Apr 24, 2023 that may be closed by this pull request
@dreamorosi dreamorosi merged commit 1077366 into aws-powertools:main Apr 24, 2023
@arnabrahman
Copy link
Contributor Author

Happy to help

@arnabrahman arnabrahman deleted the 163-metrics-unit-tests branch April 25, 2023 03:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature PRs that introduce new features or minor changes size/XXL PRs with 1K+ LOC, largely documentation related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Maintenance: metrics unit testing strategy
2 participants