Skip to content

Overhaul Packages Testing #1347

@josecelano

Description

@josecelano

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

Sub-issues

Metadata

Metadata

Assignees

No one assigned

    Labels

    - Developer -Torrust Improvement ExperienceEPICContains several subissuesHelp WantedMore Contributions are Appreciated and extra attention is needed.Quality & AssuranceRelates to QA, Testing, and CITestingChecking Torrust

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions