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

Overhaul Packages Testing #1347

Open
josecelano opened this issue Mar 3, 2025 · 0 comments
Open

Overhaul Packages Testing #1347

josecelano opened this issue Mar 3, 2025 · 0 comments
Labels
- Developer - Torrust Improvement Experience EPIC Contains several subissues Help Wanted More Contributions are Appreciated and extra attention is needed. Quality & Assurance Relates to QA, Testing, and CI Testing Checking Torrust

Comments

@josecelano
Copy link
Member

josecelano commented Mar 3, 2025

Add unit tests to all workspace packages in the Torrust Tracker.

After the refactoring packages and the extraction of many new packages, which can be found here, we now have a better structure.

While we have good test coverage due to a robust E2E test suite, writing unit tests for individual packages is critical as we publish these new crates.

Objective

Our goal is to review and enhance the unit test coverage for all packages, focusing on critical features to ensure robustness and reliability. Given the recent overhaul of the tracker core, writing unit tests for these packages should be much easier.

This is a great opportunity for newcomers to dive into the Torrust Tracker project, learning about BitTorrent, Rust, and our core architecture.

How to Proceed

  1. Sub-Issue Creation:

    • Open a new sub-issue for each package. I'll start by creating some with additional comments or suggestions.
    • Write down in the issue the initial code coverage for the package.
  2. Test Existing Structures:

    • Refer to the tracker-core package as it already has good test coverage.
  3. Expand Tests:

    • Whenever possible, add integration tests or examples. For server packages (*-server), consider creating examples such as running a program with a single HTTP tracker.

You can generate the coverage report for a package with:

cargo llvm-cov --package bittorrent-tracker-core
cargo llvm-cov --package PACKAGE_NAME (the name in the `Config.toml` file).

Best Practices

  • Group Tests by Responsibilities:

    • Avoid testing one public method at a time. Focus on the module or class's responsibility, and test the behavior. Revisiting the code during testing often leads to valuable refactoring opportunities.
  • Test Maintenance:

    • Take your time to ensure tests are maintainable. They are as important as production code and often serve as a foundation for more production code.
  • Readable Test Outputs:

    • Organize tests so their outputs read like a contract. See an example here.
  • Simplicity with AAA:

    • Stick to the AAA pattern (Arrange, Act, Assert) to keep tests simple and comprehensible.
  • Share Your Innovations:

    • If you implement something innovative, consider discussing or sharing it here.
  • Manageable Workloads:

    • Split issues into manageable portions. Each issue should represent about a day's work, focusing on a single module or functionality. This makes the review process simpler and expedites merging.
  • Tools for Assistance:

  • Optimized IDE Usage:

    • Boost efficiency by opening and testing one package at a time with your IDE instead of loading the entire repository.

Inspiration

If you are looking for some examples. Here you have some issues related to adding tests to the tracker core package:

NOTICE: not all sub-issues have been opened. Feel free to open new issues for other packages.

cc @da2ce7 @mario-nt

@josecelano josecelano added - Developer - Torrust Improvement Experience EPIC Contains several subissues Quality & Assurance Relates to QA, Testing, and CI Testing Checking Torrust Help Wanted More Contributions are Appreciated and extra attention is needed. labels Mar 3, 2025
@josecelano josecelano pinned this issue Mar 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
- Developer - Torrust Improvement Experience EPIC Contains several subissues Help Wanted More Contributions are Appreciated and extra attention is needed. Quality & Assurance Relates to QA, Testing, and CI Testing Checking Torrust
Projects
None yet
Development

No branches or pull requests

1 participant