Skip to content

Conversation

NicolasMassart
Copy link
Contributor

@NicolasMassart NicolasMassart commented Mar 7, 2025

Test Naming Guidelines Update

Updates our test naming conventions to improve clarity and maintainability of our test suite.

Key Changes

  • Established clear guidelines for naming unit tests
  • Added examples of good and bad practices
  • Introduced principles for more descriptive and concise test names

Note

Overhauls unit testing guidelines with clearer naming conventions, scenario grouping, isolation practices, and snapshot usage, adding concise rules and expanded examples.

  • Docs: docs/testing/unit-testing.md
    • Naming & Structure:
      • Clarifies describe usage (by function and scenario) and it descriptions with action-oriented, behavior-focused phrasing; de-emphasizes “should”.
      • Adds comprehensive examples contrasting good vs. bad test names and scopes; avoids redundancy and implementation details.
    • Test Focus & Private Code:
      • Reinforces single-behavior tests and testing via public interfaces (not private methods), with illustrative examples.
    • Test Phases & Readability:
      • Highlights setup/exercise/verify/teardown phases and spacing to improve readability, with before/after examples.
    • Isolation Practices:
      • Advises resetting mocks (resetMocks, restoreMocks), handling globals via spies/wrappers/DI, and replacing shared vars with factories.
      • Recommends avoiding beforeEach in favor of setup helpers/wrappers; includes teardown pattern.
    • Mocks & Snapshots:
      • Prefers Jest mocks over Sinon; cautions on general manual mocks.
      • Refines snapshot test naming to reflect “matches rendered snapshot” and clarifies snapshot limitations.

Written by Cursor Bugbot for commit f9e4a92. This will update automatically on new commits. Configure here.

@NicolasMassart NicolasMassart added the enhancement New feature or request label Mar 7, 2025
@NicolasMassart NicolasMassart self-assigned this Mar 7, 2025
@NicolasMassart NicolasMassart requested a review from a team as a code owner March 7, 2025 18:19
@NicolasMassart NicolasMassart moved this to Needs dev review in PR review queue Mar 7, 2025
@NicolasMassart NicolasMassart changed the title update unit test naming guidelines Update unit test naming guidelines Mar 7, 2025
@NicolasMassart NicolasMassart requested a review from Copilot March 11, 2025 13:27
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates our unit test naming guidelines to improve clarity and maintainability of our test suite.

  • Added a structured set of instructions for naming tests using active verbs.
  • Included new examples of both poor ("Don't") and good ("Do") naming practices.
  • Provided an extended list of considerations to ensure test names are descriptive and concise.
Comments suppressed due to low confidence (1)

docs/testing/unit-testing.md:125

  • [nitpick] The test name in this example includes the 'should' prefix even though the guidelines recommend avoiding it. Consider revising the test name to remove the 'should' prefix and focus directly on the behavior.
it('should successfully add token when address is valid and decimals are set and symbol exists', () => {

Rsed19901

This comment was marked as spam.

avoid confusion as when I asked to use the 3rd person form for verb, this doesn't apply to "render" in "render matches snapshot" as render is not the verb here but a noun. The verb is match which is correct here as "matches".
So they replaced the correct phrase by "renders matches snapshot" which is wrong.
Remove render to avoid verb/noun confusion and anyway, render is obvious and part of the test implementation
@hieu-w hieu-w self-requested a review June 11, 2025 11:21
@NicolasMassart NicolasMassart enabled auto-merge (squash) October 10, 2025 12:12
…ions

- Break up test naming examples into pairs with explanations
- Add example for missing/unclear test descriptions
- Clarify error-related test naming (be specific about error types)
- Update snapshot test naming to 'matches rendered snapshot'
- Remove vague terms like 'gracefully' and 'handles' from examples
- Enhance guidance to avoid weasel words and subjective language
@NicolasMassart NicolasMassart requested a review from hieu-w October 17, 2025 10:52
Copilot

This comment was marked as off-topic.

@NicolasMassart NicolasMassart enabled auto-merge (squash) October 17, 2025 10:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

Status: Needs dev review

Development

Successfully merging this pull request may close these issues.

5 participants