Visual Testing Overview
The visual testing methodology is described in detail in the osu-framework wiki.
- Render UI components in real-time
- Allow manual interaction and inspection
- Can be automated with test steps
- Provide immediate visual feedback during development
Benefits of Visual Testing
Why Visual Tests?
Why Visual Tests?
- Immediate feedback - See your changes instantly without rebuilding the entire game
- Isolated testing - Test individual components in isolation
- Interactive debugging - Interact with components to test different states
- Regression prevention - Catch visual regressions before they reach production
- Documentation - Tests serve as examples of how components should be used
Test Structure
Visual tests inherit from test scene base classes and use NUnit attributes.Basic Test Example
Key Components
Test Scene Base Class
Tests inherit from base classes like:
OsuTestScene- For basic component testsScreenTestScene- For testing full screensOsuManualInputManagerTestScene- For tests requiring input controlOsuGameTestScene- For tests requiring the full game context
NUnit Attributes
Use standard NUnit attributes:
[Test]- Marks a test method[TestFixture]- Marks a test class[SetUpSteps]- Setup steps that run before each test[BackgroundDependencyLoader]- Dependency injection
Common Test Patterns
Testing a Complex Overlay
Key Patterns
Test Pattern Best Practices
Test Pattern Best Practices
1. Use SetUpSteps for common setup:2. Use descriptive step names:3. Use AddAssert for validation:4. Use AddUntilStep for async operations:5. Use AddSliderStep for interactive testing:
Test Coverage Expectations
What to Test
New UI components
All new UI components should have visual tests that demonstrate:
- Basic rendering and layout
- Different states (enabled, disabled, selected, etc.)
- User interactions (click, hover, drag, etc.)
- Edge cases and boundary conditions
Bug fixes
When fixing a bug:
- Add a test that reproduces the bug
- Verify the test fails before the fix
- Verify the test passes after the fix
Game mechanics
For gameplay features:
- Test scoring calculations
- Test mod interactions
- Test input handling
- Test visual feedback
Running Tests
Running All Tests
Running Specific Tests
Running Tests in Visual Mode
The most effective way to run visual tests is through the visual test runner, which allows you to see and interact with tests in real-time.
Run the test browser
Execute the test browser application to see an interactive list of all available tests.
Select and run tests
Navigate through the test tree and select individual tests to run them interactively.
Test Organization
Directory Structure
Naming Conventions
Test Naming Guidelines
Test Naming Guidelines
Test class names:
- Prefix with
TestScenefor visual tests:TestSceneOsuLogo - Suffix with
Testfor unit tests:BeatmapConversionTest
- Use descriptive names that explain what is being tested:
TestBasicRendering - Use
Testprefix:TestModSelection
- Use clear, action-oriented descriptions: “select hard rock mod”
- Keep them concise but descriptive: “wait for load complete”
Debugging Tests
Using Assertions
Waiting for Conditions
Inspecting State
Before Submitting PRs
Tests are a critical part of the development workflow. They help ensure code quality, prevent regressions, and serve as living documentation for how components should be used.