Refactor UserOutput tests to use rstest parameterized testing #131
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Eliminates test duplication in
UserOutputby replacing 9 near-identical test functions with 4 parameterized test functions using rstest.Changes
Added parameterized tests (4 functions generating 24 test cases)
Removed duplicate tests (9 functions)
Added test matrix documentation in code comments
Before/After
Before - adding a new message type:
After:
#[case("info", "ℹ️ Test message\n", VerbosityLevel::Normal, "stderr")]Test count: 65 → 80 user_output tests (parameterized cases expand to multiple test instances)
Total tests: 1122 (unchanged)
Coverage: Maintained, with additional verbosity level combinations
Original prompt
This section details on the original issue you should resolve
<issue_title>Parameterized Test Cases for User Output</issue_title>
<issue_description>## Overview
Refactor the
UserOutputtest suite to use parameterized tests withrstest, eliminating significant code duplication. Currently, many tests are nearly identical, differing only in the method called, expected symbol, verbosity level, and output channel. By using parameterized tests, we can express the same behavior matrix with much less code while maintaining clarity and improving maintainability.Current State: The codebase already has simplified test infrastructure (Issue #123) with
TestUserOutputhelper, providing the foundation for this refactoring.Specification
See detailed specification: docs/issues/128-parameterized-test-cases.md
(Link will be updated after issue number assignment and file rename)
🏗️ Architecture Requirements
DDD Layer: Presentation (Tests)
Module Path:
src/presentation/user_output.rs(test module)Pattern: Parameterized unit tests with rstest
Key Changes
rstestdependency toCargo.tomldev-dependenciesImplementation Plan
Phase 1: Setup and Dependencies (30 minutes)
rstest = "0.18"to dev-dependenciesPhase 2: Identify Test Patterns (1 hour)
Phase 3: Create Parameterized Channel Routing Tests (2 hours)
Phase 4: Create Parameterized Verbosity Tests (2 hours)
Phase 5: Create Parameterized Formatting Tests (1 hour)
Phase 6: Remove Duplicate Tests (1 hour)
Phase 7: Validation and Documentation (1 hour)
Phase 8: Integration Testing (30 minutes)
Estimated Total Time: ~8.5 hours
Acceptance Criteria
Quality Checks:
./scripts/pre-commit.shTask-Specific Criteria:
rstestdependency is added to dev-dependenciescargo llvm-cov)Coverage Requirements:
Related
Benefits
✅ Reduced Duplication - one test implementation covers multiple cases
✅ Easier to Extend - adding new cases is as simple as adding a
#[case(...)]line✅ Clear Specification - test cases act as behavior documentation
✅ Maintainability - changes affect one test instead of many
✅ Better Coverage - easier to ensure all combinations are tested
✅ Consistent Testing - all cases use the same testing logic
Test Matrix