Advanced Examples

December 28, 2025 · View on GitHub

Welcome to the advanced gdUnit4Net examples! This section covers sophisticated testing techniques, professional configurations, and complex scenarios you'll encounter in real-world Godot projects.

Prerequisites

Before diving into advanced examples, ensure you understand:

  • Basic gdUnit4Net concepts from Basics
  • Test project setup and configuration
  • Environment variables vs configuration files
  • Basic Godot object lifecycle and memory management

Getting Started with Advanced Topics

Ready for more complex testing? Explore in this order:

  1. Global Test Settings - Professional test configuration using .runsettings files
  2. Compile-time Analysis - Static analysis and error prevention with gdUnit4.analyzers
  3. Multi-Project Testing - Separate test and production projects with symlinks
  4. Complex Test Scenarios - Advanced testing patterns and techniques

Advanced Topics Structure

The advanced examples are organized into:

├── Setup/              # Advanced project configurations
   ├── TestWithRunsettings/    # Professional test settings configuration
   ├── TestWithAnalyzers/      # Compile-time validation and code analysis 
   └── MultiProjectSetup/      # Multi-project architecture with symlinks
└── Tests/              # Complex testing scenarios and patterns
    ├── SceneTesting/           # Scene loading, lifecycle, and interaction testing
    ├── InputTesting/           # Mouse, keyboard, and user input simulation
    ├── SignalTesting/          # Signal emission, monitoring, and workflow testing
    └── ExceptionTesting/       # Standard and Godot-specific exception handling

What Each Section Covers

Setup/

Professional project configurations for production-ready test environments:

  • TestWithRunsettings: Centralized configuration using .runsettings files

    • Alternative to environment variables for team and CI/CD scenarios
    • Multiple output formats and advanced logging
    • Environment-specific configurations
    • Better IDE integration and consistent team settings
  • TestWithAnalyzers: Compile-time validation with gdUnit4.analyzers

    • Static analysis to catch common testing mistakes at compile time
    • Prevents runtime errors by detecting missing [RequireGodotRuntime] attributes
    • IDE integration with real-time feedback and quick fixes
    • Enforces gdUnit4Net best practices automatically
    • Improves developer productivity and code quality
  • MultiProjectSetup: Separate test and production projects architecture

    • Clean separation between production and test code
    • Symbolic links for resource path preservation
    • Single assembly compilation without code duplication
    • Cross-platform compatibility (Windows, Linux, macOS)
    • Git-friendly setup with proper .gitignore configuration

Tests/

Advanced testing patterns and complex scenarios:

  • Scene Testing: Loading, managing, and testing Godot scenes

    • Suite-level vs per-test scene loading strategies
    • Scene lifecycle management and memory optimization
  • Input Testing: Comprehensive user input simulation and validation

    • Mouse input: positioning, clicking, hover detection
    • Keyboard input: key combinations, modifiers, text input processing
    • Input state validation through both Godot's Input singleton and scene properties
    • UI element interaction testing with precise event simulation
  • Signal Testing: Godot signal communication and workflow validation

    • Basic signal emission and monitoring with timeout handling
    • Signal chaining and asynchronous workflow testing
    • Signal parameter validation and emission counting
    • Integration between input events and signal-driven game logic
  • Exception Testing: Robust error handling and exception validation

    • Standard C# exception testing (ArgumentException, NullReferenceException, etc.)
    • Godot-specific exception monitoring with [GodotExceptionMonitor] attribute
    • Silent exception detection during frame processing and node lifecycle
    • Integration between Godot error reporting (GD.PushError) and test failures

Key Concepts You'll Learn

Project Architecture

  • Multi-project solution organization for large codebases
  • Symbolic link strategies for resource sharing
  • Clean separation of concerns between test and production
  • Managing dependencies and references effectively

Configuration Management

  • Using .runsettings for team consistency and CI/CD integration
  • Environment-specific test configurations
  • Advanced logging and reporting options
  • Static analysis integration for error prevention

Code Quality and Analysis

  • Compile-time validation of test code
  • Preventing common gdUnit4Net mistakes before runtime
  • IDE integration for immediate feedback
  • Enforcing coding standards and best practices

Testing Strategies

  • Scene-based testing patterns for UI and game logic
  • Input simulation for realistic user interaction testing
  • Signal-driven architecture testing and validation
  • Exception monitoring for robust error handling
  • Isolation techniques for complex dependencies

Production Readiness

  • Test organization for large codebases
  • Continuous integration best practices
  • Test reporting and documentation
  • Debugging complex test failures

Complexity Progression

LevelFocusExamples
BasicsLearning fundamentalsSimple assertions, basic setup
AdvancedProfessional techniquesMulti-project architecture, configuration management, static analysis, complex testing scenarios

When to Use Advanced Techniques

Use Multi-Project Setup When

  • ✅ Large projects requiring extensive test coverage
  • ✅ Team projects with dedicated QA/test developers
  • ✅ Production builds where size and dependencies matter
  • ✅ Projects following enterprise architecture patterns
  • ✅ Need different build configurations for test vs production

Use Advanced Configuration When

  • ✅ Working in a team environment
  • ✅ Setting up CI/CD pipelines
  • ✅ Need multiple test output formats
  • ✅ Managing different environments (dev, staging, prod)
  • ✅ Want consistent configuration across team members

Use Static Analysis When

  • ✅ Teams wanting to enforce gdUnit4Net best practices automatically
  • ✅ Projects requiring high test reliability and quality
  • ✅ Developers who want immediate feedback on testing mistakes
  • ✅ Codebases with many contributors to maintain consistency
  • ✅ CI/CD pipelines that should fail fast on test configuration errors

Use Advanced Testing When

  • ✅ Testing complex Godot scenes with multiple components
  • ✅ Validating user input handling and UI interactions
  • ✅ Testing signal-driven game logic and communication patterns
  • ✅ Need comprehensive exception handling and error recovery testing
  • ✅ Working with large, complex game systems requiring isolation

Testing Patterns Overview

PatternUse CaseKey Benefits
Scene TestingUI components, game objectsRealistic testing environment, component integration
Input TestingUser interactions, controlsPrecise input simulation, state validation
Signal TestingEvent-driven logic, workflowsCommunication pattern validation, timing verification
Exception TestingError handling, robustnessSilent failure detection, comprehensive error coverage

Setup Examples Comparison

AspectTestWithRunsettingsMultiProjectSetupTestWithAnalyzers
Primary FocusTest execution configurationProject architectureCode quality and error prevention
Configuration Method.runsettings filesSymbolic links & .csprojgdUnit4.analyzers package
Team BenefitsConsistent test settingsClean code separationEnforced coding standards
CI/CD IntegrationMultiple output formatsIsolated test environmentEarly error detection
Developer ExperienceProfessional test reportsBetter IDE performanceReal-time feedback in IDE
Error PreventionRuntime configuration issuesAssembly conflicts (CS0436)Compile-time validation
Best ForTeam environmentsLarge projectsCode quality enforcement

Project Architecture Comparison

AspectSingle ProjectMulti-Project with CopyMulti-Project with Symlinks
Resource PathsDirect accessPath adjustments neededOriginal paths preserved
Build TimeFastestSlower (file copying)Fast (symlink creation)
Disk UsageMinimalDuplicated resourcesMinimal (symlinks)
Git ComplexitySimpleComplex (duplicates)Simple (symlinks ignored)
Team WorkflowMixed codeClean separationClean separation
MaintenanceHarderMediumEasiest

Next Steps

After mastering advanced techniques:

  • Apply learned concepts to your own projects
  • Combine multi-project architecture with .runsettings configuration
  • Add analyzer validation to your test projects
  • Integrate scene, input, signal, and exception testing patterns
  • Explore integration with external testing tools
  • Share your testing strategies with the community

Contributing Advanced Examples

Have an advanced testing scenario not covered here? We welcome contributions!