chore: refactor Native tests using Theory and helper methods to reduce duplication #381
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.
This PR refactors the tests for
DevantlerTech.KubernetesGenerator.Native
to be more concise while maintaining full code coverage. The refactoring addresses significant duplication and boilerplate in the test suite by leveraging xUnit's Theory, InlineData, and MemberData features along with helper methods.Key Improvements
1. Theory Tests with InlineData for Simple Variations
Consolidated tests that only differ in simple parameter values:
2. Theory Tests with MemberData for Complex Scenarios
Grouped related test cases that differ in model configuration:
3. Centralized Exception Testing
4. Helper Methods for Common Operations
Added private
GenerateAndVerifyAsync
helper methods in each test class to eliminate repeated file operation boilerplate (create temp file → generate → read → verify → cleanup).Impact
Before: 33 test files with ~5,267 lines containing significant duplication
After: Same 33 test files with ~5,252 lines (15 line reduction in sample)
Example: DeploymentGeneratorTests reduced from 211 lines to 139 lines (34% reduction) while maintaining identical test coverage.
Projected: If applied consistently across all test files, this approach could reduce the test suite by approximately 30% (~1,580 lines) while improving maintainability.
Benefits
The refactoring demonstrates effective use of xUnit's Theory capabilities to create more maintainable and concise test code without sacrificing coverage or clarity.
Fixes #380.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.