### Install .NET 9.0 SDK Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/README.md If .NET 9.0 is not installed, download it from the official .NET download page and follow the installation instructions. ```bash dotnet --list-sdks 7.0.404 [C:\Program Files\dotnet\sdk] 8.0.411 [C:\Program Files\dotnet\sdk] 9.0.304 [C:\Program Files\dotnet\sdk] ``` -------------------------------- ### Directory Structure for Advanced Examples Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/README.md This snippet shows the directory structure for organizing advanced gdUnit4Net examples, including setup configurations and various testing scenarios. ```shell ├── 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 ``` -------------------------------- ### Verify Installed .NET SDKs Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/README.md Check the installed .NET SDK versions. Ensure .NET 9.0.x is listed. ```bash dotnet --list-sdks 7.0.404 [C:\Program Files\dotnet\sdk] 8.0.411 [C:\Program Files\dotnet\sdk] ``` -------------------------------- ### CI/CD Environment .runsettings Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithRunsettings/README.md Example of a .runsettings file for a CI/CD environment, specifying Godot executable path and common parameters for headless execution. ```xml /usr/local/bin/godot --headless --disable-render-loop ``` -------------------------------- ### Navigate to Test Project and Run Tests Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Change directory to the test project and execute the tests using the .NET CLI. This verifies the setup and runs the unit tests. ```bash cd ExampleProject.Test dotnet test ``` -------------------------------- ### Development Environment .runsettings Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithRunsettings/README.md Example of a .runsettings file tailored for a development environment, specifying Godot executable path and verbosity. ```xml C:\\Godot\\Godot.exe detailed ``` -------------------------------- ### XML Documentation Example Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/README.md Document classes and methods using XML documentation tags. This example shows documentation for a test case comparing Godot.Vector2 instances. ```csharp /// /// Demonstrates comparing two Godot.Vector2 instances. /// /// This test verifies that Godot's Vector2 equality comparison works correctly. /// Note that this is testing Godot's Vector2 type, not the System.Numerics.Vector2 type. /// [TestCase] public void CompareGodotVector2() => AssertThat(new Vector2(1, 1)).IsEqual(new Vector2(1, 1)); ``` -------------------------------- ### Resource Loading in Main Project Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Example of loading resources (scenes and textures) from the main project using Godot's resource loading mechanism. ```csharp var scene = GD.Load("res://src/scenes/LabelScene.tscn"); var icon = GD.Load("res://src/assets/icon.png"); ``` -------------------------------- ### Clone GdUnit4Net Examples Repository Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/README.md Clone the repository to your local machine and navigate into the project directory. ```bash git clone https://github.com/MikeSchulze/gdUnit4NetExamples.git cd gdUnit4NetExamples ``` -------------------------------- ### Resource Loading in Test Project with Symlink Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Demonstrates that the same resource paths used in the main project work identically in the test project due to the symlink setup. ```csharp // Same paths work because of the symlink! var scene = GD.Load("res://src/scenes/LabelScene.tscn"); var icon = GD.Load("res://src/assets/icon.png"); ``` -------------------------------- ### Godot Object Testing Example Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Basics/README.md Shows how to test a Godot object, such as a Node, within a test that requires the Godot runtime. It includes essential cleanup using Free(). ```csharp using Godot; using GdUnit4; public class BasicsTests : GdUnit4.Tests.TestCase { [TestCase] [RequireGodotRuntime] public void GodotObjectTest() { var node = new Node(); AssertThat(node).IsNotNull(); node.Free(); // Always cleanup! } } ``` -------------------------------- ### GitHub Actions Build Step Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Example of a GitHub Actions workflow step to build the project. The `dotnet build` command automatically handles symlink creation via InitialTargets. ```yaml # GitHub Actions example - name: Build run: dotnet build # Symlink created automatically ``` -------------------------------- ### Basic Assertion Example Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Basics/README.md Demonstrates a simple assertion to check if two strings are equal. This is a fundamental pattern for verifying expected outcomes. ```csharp using Godot; using GdUnit4; public class BasicsTests : GdUnit4.Tests.TestCase { [TestCase] public void BasicAssertion() { AssertThat("Hello").IsEqual("Hello"); } } ``` -------------------------------- ### GitHub Actions Test Step Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Example of a GitHub Actions workflow step to run tests. This follows the build step and executes the tests in the CI/CD environment. ```yaml - name: Test run: dotnet test ``` -------------------------------- ### CI/CD Build Failure with Analyzer Errors Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithAnalyzers/README.md Example of a CI/CD pipeline output showing a build failure due to a gdUnit4Net analyzer error, indicating a missing attribute in a test method. ```bash # Build fails fast with clear analyzer errors dotnet build # Error: GdUnit0501: Missing [RequireGodotRuntime] in TestClass.TestMethod # Build FAILED - 1 Error(s), 0 Warning(s) ``` -------------------------------- ### DataPoint and TestCase Validation Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithAnalyzers/README.md This example illustrates the analyzer's validation of attribute combinations. It shows an invalid usage of multiple [TestCase] attributes with [DataPoint] and the correct pattern for a single [TestCase]. ```csharp // ❌ ANALYZER ERROR: Invalid attribute combination [TestCase] [TestCase] // GdUnit0201: Multiple TestCase attributes not allowed with DataPoint [DataPoint] public void InvalidCombination() { } // ✅ CORRECT: Proper attribute usage [TestCase] public void ValidTest() { } ``` -------------------------------- ### Clone Repository and Navigate Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Clone the repository and change the directory to the project root. This is the initial step for setting up the multi-project structure. ```bash git clone cd MultiProjectSetup ``` -------------------------------- ### Clone Repository and Build Project Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/README.md Clone the gdUnit4NetExamples repository and build the project using dotnet CLI. ```shell git clone https://github.com/MikeSchulze/gdUnit4NetExamples.git cd gdUnit4NetExamples donnet build ``` -------------------------------- ### Build the Project Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/README.md Build the project to restore NuGet packages and compile the code. This command also ensures consistent code quality enforcement. ```bash dotnet build ``` -------------------------------- ### GdUnit Specific Settings Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithRunsettings/README.md Customize Godot startup arguments and test identification for better test execution and reporting. ```xml FullyQualifiedName ``` -------------------------------- ### Run Tests from Solution Root Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Execute all tests in the solution from the solution's root directory using the .NET CLI. ```bash # From solution root dotnet test ``` -------------------------------- ### Project File with InitialTargets Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Configuration within the .csproj file to specify `InitialTargets='CreateSymlinks'`. This ensures the symlink creation process runs before the main build targets. ```xml ``` -------------------------------- ### RunConfiguration Settings Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithRunsettings/README.md Configure test execution parameters like CPU count, session timeout, and environment variables such as GODOT_BIN. ```xml 1 1800000 path/to/godot.exe ``` -------------------------------- ### Enable Developer Mode on Windows Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Recommended method to resolve symlink creation issues on Windows. This involves enabling Developer Mode in system settings. ```text Open Settings → Update & Security → For Developers Enable "Developer Mode" Rebuild the project ``` -------------------------------- ### Command Line Test Execution Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithRunsettings/README.md Execute tests using the dotnet CLI, specifying a .runsettings file for configuration. ```bash dotnet test --settings .runsettings ``` -------------------------------- ### CI/CD .runsettings Usage Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithRunsettings/README.md Command to run tests using a specific .runsettings file for CI/CD environments. ```bash dotnet test --settings .runsettings.ci ``` -------------------------------- ### Centralized Build Configuration Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/README.md Use Directory.Build.props to centralize build settings like enabling .NET code analyzers and treating warnings as errors. ```xml true latest All true true true ``` -------------------------------- ### Project-Level Configuration for Analyzers Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithAnalyzers/README.md Configure your .csproj file to treat all analyzer warnings as errors or specify individual analyzer warnings to be treated as errors. ```xml true GdUnit0501;GdUnit0500 ``` -------------------------------- ### Run Tests with Detailed Verbosity Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Run tests and display detailed output, which can be helpful for debugging test execution. ```bash # With specific verbosity dotnet test -v detailed ``` -------------------------------- ### Run Terminal as Administrator on Windows Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Alternative method for Windows if Developer Mode cannot be enabled. This requires running the terminal with elevated privileges. ```text Open terminal as Administrator Navigate to project directory Run `dotnet build` ``` -------------------------------- ### Set GODOT_BIN Environment Variable (Windows) Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Basics/Setup/RequireGodotTestProjectSetup/README.md Configure the GODOT_BIN environment variable on Windows to point to the Godot executable. This is required for tests that use the [RequireGodotRuntime] attribute. ```cmd set GODOT_BIN=C:\path\to\Godot_v4.4.1-stable_mono_win64.exe ``` -------------------------------- ### Test Project Configuration with GdUnit4 Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Configures a .NET test project for GdUnit4, setting the target framework, root namespace, and necessary package references. It ensures all dependencies are copied for test execution and identifies the project as a GdUnit4 test project. ```xml net9.0 GdUnit4.Examples.Advanced.Setup.MultiProjectSetup true GdUnit4 ``` -------------------------------- ### Godot Runtime Not Configured Error Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Basics/Setup/RequireGodotTestProjectSetup/README.md This error message indicates that the GODOT_BIN environment variable is not set or is empty, preventing tests requiring the Godot runtime from running. ```text Godot runtime is not configured. The environment variable 'GODOT_BIN' is not set or empty. Please set it to the Godot executable path. No test is available in [...].dll ``` -------------------------------- ### Set GODOT_BIN Environment Variable (Linux/macOS) Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Basics/Setup/RequireGodotTestProjectSetup/README.md Configure the GODOT_BIN environment variable on Linux or macOS to point to the Godot executable. This is required for tests that use the [RequireGodotRuntime] attribute. ```bash export GODOT_BIN=/path/to/Godot_v4.4.1-stable_mono_linux64 ``` -------------------------------- ### Symbolic Link Creation Target for MSBuild Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md An MSBuild target that runs before project evaluation to create symbolic links for source directories. This ensures that the test project can access production code and resources as if they were part of its own structure, supporting cross-platform compatibility. ```xml $([System.IO.Path]::GetFullPath('$(MSBuildProjectDirectory)/../ExampleProject/src')) $(MSBuildProjectDirectory)/src ``` -------------------------------- ### LoggerRunSettings for Test Reports Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithRunsettings/README.md Enable different logger formats for test results, including HTML for rich reports and TRX for CI/CD integration. ```xml ``` -------------------------------- ### VS Code Run Settings Configuration Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithRunsettings/README.md Configure the test explorer in VS Code to use a specific .runsettings file for test execution. ```json { "dotnet-test-explorer.runSettingsPath": ".runsettings" } ``` -------------------------------- ### Ruleset File Configuration for gdUnit4Net Analyzers Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithAnalyzers/README.md Define specific rules and their actions (Error, Warning, None) for the gdUnit4.analyzers in a .ruleset file for complex projects. ```xml ``` -------------------------------- ### Basic Test Class Structure Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Basics/README.md Defines a simple test class with a test method. Ensure your test class is marked with [TestSuite] and test methods with [TestCase]. ```csharp [TestSuite] public class MyTestClass { [TestCase] public void MyTest() { /* test code */ } } ``` -------------------------------- ### Junction Fallback Command on Windows Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Command to create a directory junction on Windows, used as a fallback if symlink creation fails. This is automatically handled by the project. ```cmd mklink /J src ..\ExampleProject\src ``` -------------------------------- ### Memory Management: Freeing Godot Objects Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Basics/Setup/RequireGodotTestProjectSetup/README.md Demonstrates the importance of calling Free() on Godot objects after testing to prevent memory leaks. This is a key learning point for Godot runtime testing. ```csharp // Always call Free() on Godot objects to prevent leaks ``` -------------------------------- ### Enable/Disable Specific Rules with .editorconfig Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithAnalyzers/README.md This configuration snippet shows how to manage analyzer rules using an .editorconfig file. It demonstrates promoting errors to warnings and disabling specific rules. ```ini [*.cs] # Promote errors to warnings for stricter enforcement dotnet_diagnostic.GdUnit0501.severity = warning # Disable specific rules if needed dotnet_diagnostic.GdUnit0201.severity = none ``` -------------------------------- ### Run Tests with a Filter Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Execute only specific tests by filtering based on their fully qualified name. This is useful for targeting particular test cases. ```bash # With filter dotnet test --filter "FullyQualifiedName~CalculatorTest" ``` -------------------------------- ### Git Ignore for Test Project Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/MultiProjectSetup/README.md Specifies files and directories to be ignored by Git within the test project. Crucially, it excludes the symlinked 'src' folder to prevent it from being committed to version control. ```gitignore # .gitignore in test project .godot/ src # Symlinked folder - don't commit ``` -------------------------------- ### C# Test Case Missing Godot Runtime Attribute Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithAnalyzers/README.md This C# code snippet demonstrates a test case that will fail at runtime because it uses Godot types without the required [RequireGodotRuntime] attribute. Analyzers will catch this at compile time. ```csharp [TestCase] // Missing [RequireGodotRuntime] public void TestNode() { var node = new Node(); // Runtime error: Godot not initialized! AssertThat(node).IsNotNull(); } ``` -------------------------------- ### Missing [RequireGodotRuntime] Detection Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithAnalyzers/README.md This snippet shows how the analyzer flags tests that use Godot types without the [RequireGodotRuntime] attribute. The correct pattern includes the attribute for valid Godot type usage. ```csharp // ❌ ANALYZER ERROR: Missing attribute when using Godot types [TestCase] public void IsNodeNotNullInvalidTest() // GdUnit0501 will flag this! { var node = AutoFree(new Node()); // Uses Godot type without [RequireGodotRuntime] AssertThat(node).IsNotNull(); } // ✅ CORRECT: Proper attribute usage [TestCase] [RequireGodotRuntime] public void IsNodeNotNull() // Analyzer approves this pattern { var node = AutoFree(new Node()); AssertThat(node).IsNotNull(); } ``` -------------------------------- ### Pure C# Test Validation Source: https://github.com/godot-gdunit-labs/gdunit4netexamples/blob/master/Examples/Advanced/Setup/TestWithAnalyzers/README.md This snippet demonstrates a valid pure C# test case that does not involve Godot types. The analyzer correctly identifies this as valid and does not issue any warnings. ```csharp // ✅ CORRECT: Pure C# test doesn't need special attributes [TestCase] public void TestPureCSharpObject() // No Godot types = no warnings { var player = new { Name = "Hero", Level = 10 }; AssertThat(player.Name).IsEqual("Hero"); } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.