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

Maintenance: metrics unit testing strategy #163

Closed
alan-churley opened this issue Aug 6, 2021 · 15 comments · Fixed by #1414
Closed

Maintenance: metrics unit testing strategy #163

alan-churley opened this issue Aug 6, 2021 · 15 comments · Fixed by #1414
Assignees
Labels
completed This item is complete and has been merged/shipped good-first-issue Something that is suitable for those who want to start contributing metrics This item relates to the Metrics Utility tests PRs that add or change tests

Comments

@alan-churley
Copy link
Contributor

Description of the feature request

Problem statement
Metrics unit tests currently are not structured the same as the Logger module,

In the logger only public methods are tested, following the recommendations here: https://github.com/goldbergyoni/javascript-testing-best-practices/#-%EF%B8%8F-14-stick-to-black-box-testing-test-only-public-methods

Opening a ticket to track discussions and work on improving this,

Related issues, RFCs

#102

@alan-churley alan-churley mentioned this issue Aug 6, 2021
12 tasks
@dreamorosi dreamorosi added duplicate This issue is a duplicate of an existing one metrics This item relates to the Metrics Utility enhancement good-first-issue Something that is suitable for those who want to start contributing and removed duplicate This issue is a duplicate of an existing one labels Aug 11, 2021
@dreamorosi dreamorosi added this to the production-ready-release milestone Dec 10, 2021
@saragerion saragerion removed this from the production-ready-release milestone May 16, 2022
@dreamorosi dreamorosi added the triage This item has not been triaged by a maintainer, please wait label Nov 9, 2022
@dreamorosi
Copy link
Contributor

The issue is still current so contributions are welcome.

This is a good issue for newcomers as it allows to understand how the utility works in depth, as well as for those who are looking at sharpening their Jest skills.

If anyone is interested in picking this up, please leave a comment here, then discuss your findings / proposed changes before opening a PR.

@dreamorosi dreamorosi removed enhancement triage This item has not been triaged by a maintainer, please wait labels Nov 13, 2022
@dreamorosi dreamorosi added help-wanted We would really appreciate some support from community for this one tests PRs that add or change tests confirmed The scope is clear, ready for implementation labels Nov 13, 2022
@dreamorosi dreamorosi changed the title metrics: unit testing strategy Maintenance: metrics unit testing strategy Nov 14, 2022
@arnabrahman
Copy link
Contributor

@dreamorosi Interested, I will look into this & share my findings.

@dreamorosi
Copy link
Contributor

Hi @arnabrahman, thank you for your interest in this issue ✨!

Looking forward to review / collaborate on your proposal and findings in the issue.

If you have any question while you look into it, please let me know both here or on our Discord.

@arnabrahman
Copy link
Contributor

Hello @dreamorosi, sorry for replying late to this.

I think this particular issue was first mentioned here by @saragerion . After looking at both the unit tests for Logger/Tracer, my understanding of what she meant by the issue is, in the Logger/Tracer package all the tests are written for public functions rather than testing a particular feature of the package. But in Metrics, here we are following a pattern of testing a particular behavior/feature of Metrics rather than taking a single function & testing every case of that function.

So, if we want to follow a similar pattern/structure for Metrics similar to Logger/Tracer, we would take a function & test every case of that function. For example, for addMetric function, we want to test

  • the behavior when a new metric is added
  • the behavior when an old metric is added
  • the behavior when adding a single metric (for single metric, it will publish StoredMetrics)

We can take this approach & apply it to every public function of Metrics.

These are my findings. I might be wrong about this, so let me know if i am in the right direction or not. Thanks 🙂

@dreamorosi
Copy link
Contributor

Hi @arnabrahman thank you for taking the time to look into this!

Your findings are spot on, and this is indeed the direction that I think we should be going with this issue.

On top of the points you discussed above, as part of this issue I think we should:

  • Maintain 100% coverage
  • Adapt the style and convention used in the Logger/Tracer unit tests (i.e. comments, spacing, etc.)
  • Whenever needed/possible, extract common setup / utilities in helper functions

If you're still interested in working on this issue, feel free to start working on a PR. I'll be happy to continue the conversation there.

@arnabrahman
Copy link
Contributor

arnabrahman commented Mar 19, 2023

@dreamorosi Yes, i am very much interested to work on this & contribute. I will start on a PR soon & will also follow your suggestions.

@dreamorosi dreamorosi removed the help-wanted We would really appreciate some support from community for this one label Mar 19, 2023
@dreamorosi dreamorosi moved this from Backlog to Working on it in AWS Lambda Powertools for TypeScript Mar 19, 2023
@dreamorosi
Copy link
Contributor

Great, I have assigned the issue to you and change its status to "Working on it".

If you have any question during the implementation don't hesitate to reach out here or on Discord!

@niko-achilles
Copy link
Contributor

Having the opportunity to introduce a new functionality for high resolution metrics and written tests before extending the Metrics implementation i had the following observations described in issue #1373 .
The observations relative to tests are the Points 3,4,6

Note in observation 4 ,
as contributor i wish i had tighter feedback loop when extending the metrics implementation.
In my observations i described that a solution consideration is that the Metrics tests which exercise the public methods to be of an MetricsInterface abstraction and not of the Metrics concrete implementation.

@dreamorosi
Copy link
Contributor

Hi @arnabrahman, just wanted to follow up on this issue and ask if you were still working on this. If there's any question that we can help answer please let us know!

@arnabrahman
Copy link
Contributor

Yes, currently i am working on this. I have already made progress and so far covered 100% test coverage as you have mentioned. Now, i need to work on refactoring some things, then i will be finished. Sorry, it's taking a bit time. And, yes i will let you know if i face any problem. Thanks @dreamorosi

@dreamorosi
Copy link
Contributor

dreamorosi commented Apr 5, 2023

Hey thank you for getting back to me so quickly, there's no rush at all - I just wanted to check!

FYI: I'm about to open a PR that adds 4 test cases related to a new feature on Metrics, hope it doesn't cause too much mess on your branch!

Thank you!

@arnabrahman
Copy link
Contributor

Hey thank you for getting back to me so quickly, there's no rush at all - I just wanted to check!

FYI: I'm about to open a PR that adds 4 test cases related to a new feature on Metrics, hope it doesn't cause too much mess on your branch!

Thank you!

Ok, I have a question. After I rewrite all the tests for Metrics, what will happen to the old tests? Should I keep both old tests & new tests or should I only keep the new ones?

@dreamorosi
Copy link
Contributor

If coverage of the new tests is 100% and the structure/style/etc. is in line with the other modules then we could replace the existing ones.

I'll be able to give you a concrete answer once you open a PR though.

@dreamorosi
Copy link
Contributor

Having the opportunity to introduce a new functionality for high resolution metrics and written tests before extending the Metrics implementation i had the following observations described in issue #1373 . The observations relative to tests are the Points 3,4,6

Note in observation 4 , as contributor i wish i had tighter feedback loop when extending the metrics implementation. In my observations i described that a solution consideration is that the Metrics tests which exercise the public methods to be of an MetricsInterface abstraction and not of the Metrics concrete implementation.

I'm about to merge the linked PR as the scope of this issue (as defined here) was to standardize the tests according to what is being done in the other utilities of the project.

I will provide a longer answer to all your points in the other original issue.

@github-project-automation github-project-automation bot moved this from Working on it to Coming soon in AWS Lambda Powertools for TypeScript Apr 24, 2023
@github-actions
Copy link
Contributor

⚠️ COMMENT VISIBILITY WARNING ⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

@github-actions github-actions bot added the pending-release This item has been merged and will be released soon label Apr 24, 2023
@dreamorosi dreamorosi added completed This item is complete and has been merged/shipped and removed pending-release This item has been merged and will be released soon confirmed The scope is clear, ready for implementation labels Apr 24, 2023
@dreamorosi dreamorosi moved this from Coming soon to Shipped in AWS Lambda Powertools for TypeScript Apr 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
completed This item is complete and has been merged/shipped good-first-issue Something that is suitable for those who want to start contributing metrics This item relates to the Metrics Utility tests PRs that add or change tests
Projects
None yet
5 participants