Test Overview
FG Character Extractor uses a golden file testing pattern to validate XML extraction. This approach compares generated output against pre-validated expected files to ensure consistent, correct extraction.Tests are located in
main_test.go with test data in the tests/ directory.Running Tests
Run the test suite using either Task or Go directly:The
-v flag provides verbose output showing each test step. Remove it for quieter output.Test Structure
The project includes one comprehensive integration test that validates the entire extraction pipeline.Test Files
Test Flow
TheTestRun function in main_test.go:10-43 follows this pattern:
Golden File Pattern
The golden file approach provides several benefits:Comprehensive Validation
Validates the entire output structure, not just specific fields
Regression Detection
Catches unintended changes to output format
Easy Updates
When output format changes intentionally, update the golden file
Visual Diffs
Failed tests can be inspected with standard diff tools
How Golden Files Work
- Initial Creation: Generate expected output manually, verify it’s correct, save as
expected_*.xml - Test Execution: Run extraction and compare output to golden file
- Validation: Byte-for-byte comparison ensures exact match
- Updates: When output format changes, regenerate and review golden files
Adding New Tests
To add a new test case:Verify and save golden file
Review the generated
character_*.xml file carefully. If correct, move it to the tests directory:Debugging Test Failures
When tests fail, follow these debugging steps:Compare files manually
Compare files manually
Use a diff tool to see what changed:Or use a visual diff tool:
Check file sizes
Check file sizes
Compare file sizes to identify major discrepancies:
Inspect XML structure
Inspect XML structure
Validate that both files are well-formed XML:
Review recent code changes
Review recent code changes
If the test previously passed, check what changed:
Update golden file if intentional
Update golden file if intentional
If the output change is intentional and correct:
Test Data Structure
The test database (tests/db.xml) contains:
- Fantasy Grounds campaign data with character sheets
- Sample character with ID
id-00001at level 4 - Ability scores and bonuses for skill calculation testing
- Skill list data to validate proficiency bonus calculations
- Tags to filter (
<public>,<holder*>) to test exclusion logic
tests/expected_character_id-00001_4.xml) validates:
- Correct XML structure with proper root element
- Character data extraction and filtering
- Skill total calculation (ability bonus + proficiency bonus)
- Special character escaping (
&,<,>) - Proper XML formatting and indentation
Running Tests in CI/CD
For continuous integration, run tests with additional flags:The
-race flag detects race conditions, and -coverprofile generates coverage data.Test Coverage
Check test coverage:Next Steps
Building
Learn about build commands and cross-platform compilation
Contributing
Review contribution guidelines and workflow