Test Framework
Dalamud uses xunit v3 for unit testing.Dalamud.Test/Dalamud.Test.csproj
net10.0-windows and reference the main Dalamud project.
Running Tests
Using Build Scripts
- Windows
- Command Line
NUKE Build Targets
The Test target in the build system:build/DalamudBuild.cs
- Full compilation before testing
- Tests run with same configuration (Debug/Release)
- No package restore during test execution
Test Structure
Tests are organized in theDalamud.Test project:
Writing Unit Tests
Basic Test Structure
Test Attributes
| Attribute | Purpose | Example |
|---|---|---|
[Fact] | Single test case | [Fact] public void Test() { } |
[Theory] | Data-driven test | [Theory] [InlineData(1)] public void Test(int x) { } |
[InlineData] | Provides test data | [InlineData("input", "expected")] |
[Skip] | Skip test | [Fact(Skip = "Not implemented")] |
Assertions
Common Assertions
Integration Testing
Testing Strategies
Unit test pure logic
Test components that don’t require game context:
- String parsing (SeString, game versions)
- Data structures and algorithms
- Configuration serialization
- Localization loading
Testing with Dalamud.CorePlugin
TheDalamud.CorePlugin project serves as an internal testbed:
Dalamud.CorePlugin/Dalamud.CorePlugin.csproj
- Access Dalamud internals during development
- Prototype new API features before making them public
- Test plugin-like functionality with privileged access
CI/CD Testing
GitHub Actions Workflow
Tests run automatically on every push and PR:.github/workflows/main.yml
API Compatibility Checks
Pull requests automatically verify API compatibility:API Compatibility Workflow
- Left: Current staging build from distribution
- Right: Proposed changes in the PR
Manual Testing Checklist
Before Submitting a PR
Core Functionality
Core Functionality
- Dalamud loads successfully via XIVLauncher
- All existing plugins continue to work
- No crashes during normal gameplay
- Game hooks function correctly
- Plugin installer works
UI Components
UI Components
- Settings window displays properly
- Plugin windows render correctly
- No UI scaling issues
- ImGui overlays work in windowed/fullscreen
- Color schemes apply correctly
Plugin API Changes
Plugin API Changes
- Sample plugin compiles against changes
- Breaking changes documented
- Migration path provided for developers
- API documentation updated
Performance
Performance
- No significant FPS drops
- Memory usage is reasonable
- No memory leaks over extended play
- Network performance unchanged
Debugging Tests
Visual Studio
Command Line
Test Coverage
While Dalamud doesn’t enforce coverage requirements, aim for:Coverage Goals
- Critical paths: 80%+ coverage
- Public APIs: All major code paths tested
- Bug fixes: Regression tests for each fix
- Utilities: High coverage for pure functions
Measuring Coverage
Using Coverlet:Performance Testing
Benchmarking with BenchmarkDotNet
For performance-critical code:Troubleshooting Test Failures
Test discovery fails
Test discovery fails
Symptoms: No tests appear in Test ExplorerSolutions:
- Rebuild the solution
- Clear Test Explorer cache
- Verify xunit.v3 packages are restored
- Check test class is public
Tests pass locally but fail in CI
Tests pass locally but fail in CI
Common causes:
- Environment differences (paths, culture, timezone)
- Missing test data files
- Platform-specific behavior
- Check CI logs for error details
- Ensure test data is included in project
- Use
[Fact(Skip = "CI only")]for problematic tests
Intermittent test failures
Intermittent test failures
Common causes:
- Race conditions in async code
- Shared state between tests
- Time-dependent assertions
- Use proper async/await patterns
- Ensure test isolation
- Avoid
Thread.Sleep, use proper synchronization
Best Practices
Fast Tests
Keep unit tests fast (<1s each). Move slow tests to integration category.
Isolated Tests
Each test should be independent. Don’t rely on test execution order.
Clear Names
Use descriptive test names:
MethodName_Scenario_ExpectedBehaviorArrange-Act-Assert
Structure tests clearly: setup, execute, verify.
Next Steps
Building Dalamud
Learn how to build from source
Contributing
Submit your tested changes