Repository navigation
Overhaul: Packages Testing #1347
Description
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
-
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.
-
Test Existing Structures:
- Refer to the tracker-core package as it already has good test coverage.
-
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.
- Whenever possible, add integration tests or examples. For server packages (
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:
- Add unit tests: Overhaul core Tracker: add units tests to the new
tracker-corepackage #1226 - Add integration tests: Overhaul core Tracker: add integration test #1266
NOTICE: not all sub-issues have been opened. Feel free to open new issues for other packages.
Activity
udp-tracker-corepackage #1348http-corepackage #1349[-]Overhaul Packages Testing[/-][+]Overhaul: Packages Testing[/+]41 remaining items
docs(issues): define per-file test workflow for udp server
Merge #2381: test(udp-server): [#2283] increase udp server package co…
chore(issues): archive closed issue torrust#2283 spec
Merge #2384: chore(issues): archive closed issue #2283 spec
docs(issues): move axum REST API test spec out of #1349
docs(issues): [#1348] add udp-core package testing specification
Merge #2407: docs(issues): [#1348] add udp-core package testing speci…
docs(issues): [torrust#2190] follow the maintainers' EPIC shape
docs(issues): [torrust#2190] record the EPIC assignment
docs(issues): align the torrust#1347 EPIC timestamp with its latest e…
Merge #2538: test(udp-core): [#1348] add tests to the udp-core package
Merge #2541: chore(issues): archive closed issue #1348 spec
docs(issues): [torrust#1349] keep the subissue status planned until T…
docs(issues): add issue specification for #1349
Merge #2546: docs(issues): [#1349] add issue specification for http-c…