Skip to content

refactor: Consolidate test source code to eliminate DRY violations#1683

Merged
thomhurst merged 2 commits into
mainfrom
fix/test-consolidation
Dec 30, 2025
Merged

refactor: Consolidate test source code to eliminate DRY violations#1683
thomhurst merged 2 commits into
mainfrom
fix/test-consolidation

Conversation

@thomhurst

Copy link
Copy Markdown
Owner

Summary

  • Creates TestSourceConstants.cs with shared using statements and namespace constants for analyzer tests
  • Creates SerializationTestModels.cs with shared test models (TestValues, SerializationTestModel)
  • Updates analyzer tests to use shared constants instead of duplicated strings
  • Updates serialization tests to use shared models

Fixes #1634, #1627

Test plan

  • Build passes
  • All tests pass

🤖 Generated with Claude Code

Extract duplicated test source code patterns across analyzer and serialization tests:

- Create TestSourceConstants.cs with shared module header strings for analyzer tests
- Create SerializationTestModels.cs with shared test model and values for JSON/XML/YAML tests
- Update 7 analyzer test files to use shared TestSourceConstants
- Update JsonTests, XmlTests, YamlTests to use shared SerializationTestModels

Fixes #1634, fixes #1627

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@thomhurst

Copy link
Copy Markdown
Owner Author

Summary

Refactors analyzer and serialization unit tests to eliminate code duplication by extracting shared constants and models.

Critical Issues

None found ✅

Suggestions

None - the refactoring is well-executed with proper curly brace escaping in interpolated strings and maintains all test semantics.

Verdict

APPROVE - No critical issues

This is a clean refactoring that:

  • Reduces 751 lines while adding only 423, net -328 lines
  • Properly escapes curly braces for C# interpolated verbatim strings ($@"...")
  • Correctly handles Roslyn analyzer test markup syntax ({{|#0:...|}})
  • Maintains semantic equivalence across all test cases
  • Improves maintainability by centralizing common test patterns

The shared constants approach will make future test maintenance significantly easier.

Add JsonIgnore attribute with WhenWritingNull condition to prevent
the Items property from appearing as null in serialized JSON output.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@thomhurst

Copy link
Copy Markdown
Owner Author

Summary

Consolidates duplicated test code by extracting shared constants and test models into dedicated files.

Critical Issues

None found ✅

Suggestions

String interpolation escaping: In several test files, the refactoring uses string interpolation with constants that contain interpolation markers like {|#0:...|}. This pattern works correctly, but be aware that:

  • The constants use $@"..." for verbatim interpolated strings
  • The diagnostic markers {{|#0:...|}} use double braces to escape them
  • This is intentional and correct, but verify the tests still pass to ensure the escaping is consistent

Test coverage: The refactoring touches 7 analyzer test files and 3 serialization test files. Ensure all tests pass after this change, as incorrect escaping could cause test failures.

Verdict

APPROVE - No critical issues

This is a clean refactoring that eliminates significant code duplication. The use of shared constants makes the tests more maintainable and easier to update in the future. The string interpolation approach is sound, just verify all tests pass to confirm the escaping is correct.

@thomhurst thomhurst merged commit 911632e into main Dec 30, 2025
11 of 12 checks passed
@thomhurst thomhurst deleted the fix/test-consolidation branch December 30, 2025 16:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Code smell: Test source code duplicated across analyzer test files

1 participant