### Basic .runsettings Setup
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/TestAdapter/README.md
Configure test execution behavior using a .runsettings file. This example shows basic run configuration, environment variables, and logger settings.
```xml
1../TestResults1800000trueC:\Path\To\Godot_v4.4-stable_mono_win64.exenormaltest-result.htmltest-result.trx--verboseFullyQualifiedNametrue2000010000
```
--------------------------------
### Install GdUnit4 API Package
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Api/README.md
Add the gdUnit4.api package as a reference to your project to install the GdUnit4 API.
```xml
```
--------------------------------
### Install GdUnit4Net Test Adapter
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/TestAdapter/README.md
Add the gdUnit4.test.adapter NuGet package to your test project to integrate the test adapter.
```xml
```
--------------------------------
### Example Test Filters
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/TestAdapter/README.md
Examples of applying test filters to target specific tests. Filters can be combined using logical operators like '&'.
```text
# Run only tests in a specific class
Class=CalculatorTests
```
```text
# Run tests with a specific category
TestCategory=UnitTest
```
```text
# Run tests with specific traits
Trait.Priority=High
```
```text
# Combine filters with logical operators
TestCategory=UnitTest&Trait.Owner=TeamA
```
--------------------------------
### GdUnit4 Configuration Options
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/TestAdapter/ReleaseNotes.txt
Example of how to configure gdUnit4 settings within a .runsettings file. These options control test execution behavior, such as capturing stdout and setting compile timeouts.
```xml
true--verbose --headlessFullyQualifiedName30000
```
--------------------------------
### VSTest Integration Command-Line Filters
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/README.md
Examples of using the `dotnet test` command with VSTest filters to selectively run tests based on traits, categories, or names.
```bash
# Run only fast tests
dotnet test --filter "Trait=Speed:Fast"
# Run integration tests
dotnet test --filter "Category=Integration"
# Run tests by name pattern
dotnet test --filter "FullyQualifiedName~Calculator"
# Combine multiple filters
dotnet test --filter "(Category=Integration)|(Trait=Speed:Fast)"
```
--------------------------------
### Error: Missing RequireGodotRuntime Annotation
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Analyzers/documentation/GdUnit0501.md
This example shows a test method that uses Godot functionality but lacks the `[RequireGodotRuntime]` attribute, which will result in a GdUnit0501 error.
```csharp
[TestCase] // ❌ GdUnit0501: Test method 'TestWithGodot' uses Godot functionality but is not annotated with '[RequireGodotRuntime]'.
public void TestWithGodot()
{
var instance = new Node2D()
AssertThat(instance).IsNotNull();
}
```
--------------------------------
### Run Fast Tests for PR Builds using dotnet test
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/TestAdapter/TestFilterGuide.md
Example of using the --filter argument with dotnet test to run unit and fast tests, suitable for Pull Request builds.
```bash
dotnet test --filter "TestCategory=UnitTest|TestCategory=Fast"
```
--------------------------------
### Run Integration Tests for Nightly Builds using dotnet test
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/TestAdapter/TestFilterGuide.md
Example of using the --filter argument with dotnet test to run only integration tests, typically used for nightly builds.
```bash
dotnet test --filter "TestCategory=IntegrationTest"
```
--------------------------------
### Fix: Add RequireGodotRuntime Annotation to Method
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Analyzers/documentation/GdUnit0501.md
This example demonstrates the correct way to fix the GdUnit0501 error by adding the `[RequireGodotRuntime]` attribute directly to the test method.
```csharp
[RequireGodotRuntime] // ✅ Correct: Method level annotation
[TestCase]
public void TestWithGodot()
{
var instance = new Node2D();
AssertThat(instance).IsNotNull();
}
```
--------------------------------
### OverrideFailureMessage Usage Example
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Api/ReleaseNotes.txt
Demonstrates the correct usage of OverrideFailureMessage at the beginning of an assertion chain. Using it later in the chain will result in a compile error.
```csharp
AssertString("foo").OverrideFailureMessage("Custom failure message").IsEqual("bar"); // ✅
AssertString("foo").IsEqual("bar").OverrideFailureMessage("Custom failure message"); // ❌ Compile error
```
--------------------------------
### Run Critical Tests for Quick Feedback using dotnet test
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/TestAdapter/TestFilterGuide.md
Example of filtering tests by a high priority trait using dotnet test, providing quick feedback on critical tests.
```bash
dotnet test --filter "Trait.Priority=High"
```
--------------------------------
### Fix: Add RequireGodotRuntime Annotation to Class
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Analyzers/documentation/GdUnit0501.md
This example shows how to apply the `[RequireGodotRuntime]` attribute at the class level, ensuring all test methods within that class that use Godot functionality are correctly annotated.
```csharp
[RequireGodotRuntime] // ✅ Correct: Class level annotation
public class MyTestClass
{
[TestCase]
public void TestWithGodot()
{
var instance = new Node2D();
AssertThat(instance).IsNotNull();
}
}
```
--------------------------------
### Fix: Single TestCase attribute with DataPoint
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Analyzers/documentation/GdUnit0201.md
This example demonstrates the correct way to use DataPoint attributes by ensuring only a single TestCase attribute is applied to the test method.
```csharp
[TestCase] // ✅ Correct: Single TestCase with DataPoint
[DataPoint(nameof(ArrayDataPointProperty))]
public void TestDataPointProperty(int a, int b, int expected)
{
AssertThat(a + b).IsEqual(expected);
}
```
--------------------------------
### Error: Multiple TestCase attributes with DataPoint
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Analyzers/documentation/GdUnit0201.md
This example shows the incorrect usage of multiple TestCase attributes on a method that also uses the DataPoint attribute, leading to the GdUnit0201 error.
```csharp
[TestCase]
[TestCase] // ❌ GdUnit0201: Method 'TestDataPointProperty' cannot have multiple TestCase attributes when DataPoint attribute is present
[DataPoint(nameof(ArrayDataPointProperty))]
public void TestDataPointProperty(int a, int b, int expected)
{
AssertThat(a + b).IsEqual(expected);
}
```
--------------------------------
### Run Component-Specific Tests for Feature Branches using dotnet test
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/TestAdapter/TestFilterGuide.md
Example of filtering tests by a specific component trait using dotnet test, useful for feature branch testing.
```bash
dotnet test --filter "Trait.Component=Authentication"
```
--------------------------------
### Error: Test Class Missing [RequireGodotRuntime]
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Analyzers/documentation/GdUnit0500.md
This example shows a test class that uses Godot functionality in a test hook without the required attribute, triggering the GdUnit0500 error.
```csharp
[TestSuite]
public class SceneRunnerTest // ❌ GdUnit0500: Test class 'SceneRunnerTest' contains Godot dependencies in test hooks and requires [RequireGodotRuntime] attribute
{
[Before]
public void Setup() =>
Engine.PhysicsTicksPerSecond = 60; // Using Godot Engine in test hook
[TestCase]
public void TestMethod() =>
AssertThat(true).IsTrue();
}
```
--------------------------------
### Fix: Add [RequireGodotRuntime] to Test Class
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Analyzers/documentation/GdUnit0500.md
This example demonstrates the correct way to fix the GdUnit0500 error by adding the [RequireGodotRuntime] attribute to a test class that utilizes Godot engine features in its hooks.
```csharp
[RequireGodotRuntime] // ✅ Correct: Uses [RequireGodotRuntime] for class with Godot dependencies in hooks
[TestSuite]
public class SceneRunnerTest
{
[Before]
public void Setup() =>
Engine.PhysicsTicksPerSecond = 60;
[TestCase]
public void TestMethod() =>
AssertThat(true).IsTrue();
}
```
--------------------------------
### Run Tests with .runsettings via Command Line
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/TestAdapter/README.md
Execute tests using the dotnet CLI and specify a .runsettings file with the --settings argument.
```bash
dotnet test --settings .runsettings
```
--------------------------------
### Configuring Godot Runtime Connection Timeout
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/Api/ReleaseNotes.txt
Shows how to set a custom timeout for the Godot runtime connection using the .runsettings file. This allows for more flexibility in environments with slower startup times.
```xml
10000
```
--------------------------------
### Basic GdUnit4Net C# Test Suite
Source: https://github.com/godot-gdunit-labs/gdunit4net/blob/master/README.md
Demonstrates various assertion types and test configurations including fast execution, Godot runtime requirements, exception monitoring, data-driven tests, and category/trait filtering.
```csharp
namespace GdUnit4.Tests
{
using static Assertions;
[TestSuite]
public class StringAssertTest
{
// Fast execution - no Godot runtime needed
[TestCase]
public void IsEqual()
{
AssertThat("This is a test message").IsEqual("This is a test message");
}
// Godot runtime required for Node operations
[TestCase]
[RequireGodotRuntime]
public void TestGodotNode()
{
AssertThat(new Node2D()).IsNotNull();
}
// Exception monitoring for Godot-specific errors
[Test]
[RequireGodotRuntime]
[GodotExceptionMonitor]
public void TestNodeCallback()
{
var node = new MyNode(); // Will catch exceptions in _Ready()
AddChild(node);
}
// Data-driven tests with dynamic test data
[Test]
[DataPoint(nameof(TestData))]
public void TestCalculations(int a, int b, int expected)
{
AssertThat(Calculator.Add(a, b)).IsEqual(expected);
}
// Exception validation with specific messages
[Test]
[ThrowsException(typeof(ArgumentNullException), "Value cannot be null")]
public void TestValidation()
{
Calculator.Add(null, 5);
}
// Test categories and traits for filtering
[Test]
[Category("Integration")]
[Trait("Speed", "Fast")]
public void FastIntegrationTest()
{
// This test can be filtered by category or trait
}
// Data source for parameterized tests
public static IEnumerable