gdUnit4.api
5.1.0-rc6
dotnet add package gdUnit4.api --version 5.1.0-rc6
NuGet\Install-Package gdUnit4.api -Version 5.1.0-rc6
<PackageReference Include="gdUnit4.api" Version="5.1.0-rc6" />
<PackageVersion Include="gdUnit4.api" Version="5.1.0-rc6" />
<PackageReference Include="gdUnit4.api" />
paket add gdUnit4.api --version 5.1.0-rc6
#r "nuget: gdUnit4.api, 5.1.0-rc6"
#:package gdUnit4.api@5.1.0-rc6
#addin nuget:?package=gdUnit4.api&version=5.1.0-rc6&prerelease
#tool nuget:?package=gdUnit4.api&version=5.1.0-rc6&prerelease
The C# GdUnit4 API
What is GdUnit4.Api
gdUnit4.api is the C# package to enable GdUnit4 to run/write unit tests in C#.
Features
- Writing And Executing Tests in C# for Net8.0 and Net10.0 C#14
- Convenient interface for running test-suites directly from Godot<br> One of the main features of GdUnit4 is the ability to run test-suites directly from the Godot editor using the context menu. You can run test-suites from the FileSystem panel, the ScriptEditor, or the GdUnit Inspector. To do this, simply right-click on the desired test-suite or test-case and select "Run Test(s)" from the context menu. This will run the selected tests and display the results in the GdUnit Inspector.<br> You can create new test cases directly from the ScriptEditor by right-clicking on the function you want to test and selecting "Create TestCase" from the context menu.
- Fluent Syntax for writing test cases that's easy to read and understand
- Wide range of Assertions for verifying the behavior and output of your code
- Test Fuzzing support: for generating random inputs to test edge cases and boundary conditions
- Parameterized Tests: (Test Cases) for testing functions with multiple sets of inputs and expected outputs
- Dynamic Tests Data: 'DataPoint' attribute to define test data sets
- Scene runner: for simulating different kinds of inputs and actions, such as mouse clicks and keyboard inputs<br> For example, you can simulate mouse clicks and keyboard inputs by calling the appropriate methods on the runner instance. Additionally, you can wait for a specific signal to be emitted by the scene, or you can wait for a specific function to return a certain value.
- Integration with Test Adapter: Works seamlessly with the gdUnit4.test.adapter for running tests in Visual Studio, VS Code, and JetBrains Rider
Installation
You can install the GdUnit4 API by adding it as a package reference to your project:
<PackageReference Include="gdUnit4.api" Version="5.0.0"/>
Related Packages
- gdUnit4.test.adapter - Run your tests in Visual Studio, VS Code, and JetBrains Rider
- gdUnit4.analyzers - Add compile-time validation for your test code
Short Example
namespace GdUnit4.Tests
{
using static Assertions;
[TestSuite]
public class StringAssertTest
{
[TestCase]
public void IsEqual()
{
AssertThat("This is a test message").IsEqual("This is a test message");
}
[TestCase]
[RequireGodotRuntime] // ← Add this for Godot-dependent tests
public void IsEqual()
{
AssertThat(new Node2D()).IsNotNull();
}
[Test]
[RequireGodotRuntime]
[GodotExceptionMonitor] // ← Monitor Godot exceptions
public void TestNodeCallback()
{
var node = new MyNode(); // Will catch exceptions in _Ready()
AddChild(node);
}
[Test]
[DataPoint(nameof(TestData))] // ← Data-driven tests
public void TestCalculations(int a, int b, int expected)
{
AssertThat(Calculator.Add(a, b)).IsEqual(expected);
}
[Test]
[ThrowsException(typeof(ArgumentNullException), "Value cannot be null")]
public void TestValidation()
{
Calculator.Add(null, 5); // Expects specific exception
}
// Data source for parameterized tests
public static IEnumerable<object[]> TestData => new[]
{
new object[] { 1, 2, 3 },
new object[] { 5, 7, 12 }
};
}
}
Documentation
For more information, check out the complete API documentation.
You are welcome to
Thank you for supporting my project
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- GodotSharp (>= 4.7.0)
- Microsoft.CodeAnalysis.CSharp (>= 5.0.0)
- Mono.Cecil (>= 0.11.6)
-
net8.0
- GodotSharp (>= 4.7.0)
- Microsoft.CodeAnalysis.CSharp (>= 5.0.0)
- Mono.Cecil (>= 0.11.6)
NuGet packages (1)
Showing the top 1 NuGet packages that depend on gdUnit4.api:
| Package | Downloads |
|---|---|
|
gdUnit4.test.adapter
GdUnit4 Test Adapter is the test adapter to run GdUnit4 tests in C#. |
GitHub repositories (7)
Showing the top 7 popular GitHub repositories that depend on gdUnit4.api:
| Repository | Stars |
|---|---|
|
Revolutionary-Games/Thrive
The main repository for the development of the evolution game Thrive.
|
|
|
luxkun/ReGoap
Generic C# GOAP (Goal Oriented Action Planning) library with Unity3d examples
|
|
|
godot-gdunit-labs/gdUnit4Net
Official C# implementation of GDUnit4 - a comprehensive unit testing framework for Godot 4. Features VS/Rider test adapter integration, parameterized tests, scene runners, and extensive assertion methods.
|
|
|
CSharpGodotTools/Template
A template used for quickly setting up new Godot 4 C# games that features ENet multiplayer, visual in-game debugging and more.
|
|
|
ShenCiao/Ciallo
The next-generation vector paint program built with Godot C#.
|
|
|
Delsin-Yu/GDTask.Nuget
Nuget package for adding async/await functionality in Godot
|
|
|
emptylower/STS2-Game-Lobby
《Slay the Spire 2》第三方联机大厅方案 | Third-party multiplayer lobby mod for Slay the Spire 2 — client MOD + lobby service + relay fallback
|
v5.1.0
**BREAKING CHANGES:**
* GD-477, GD-522: The minimum supported Godot version is now 4.7, older Godot versions are no longer supported.
Projects using Godot 4.6 or older must upgrade to Godot 4.7 or newer.
🪲 Bug Fixes
* GD-305: Added missing AppendFailureMessage on assertions
* GD-311: Catch possible exceptions on command execution and report them as InternalServerError.
* GD-317: Fixing [IgnoreUntil] is not skipping the test.
* GD-318: Fixing object deep equal comparison.
* GD-319: Fixing SceneRunner.Scene() returns disposed object after the scene is auto freed.
* GD-320: Fixing method Chaining on Asserts breaks type inference after base interface methods,
fixes also dynamic assert bindings (missing public access).
* GD-331: Fixing SceneRunner SimulateKey to provide missing Unicode
* GD-333: Fixing broken Signal assertion task handling
* GD-339: Fixing to allow single `NULL` value as TestCase argument e.g `[TestCase(null)]`
* GD-340: Fixing GdUnit4NetApiGodotBridge test discovery on linux paths
* GD-348: Fixing task handling using AwaitMethod with WithTimeout
* GD-366: Fixing `NO Godot C# SUPPORT NOT DETECTED` by increasing the used timeout to capture the supported arguments
* GD-436: Fixing named pipe collision when running multiple assemblies in parallel
* GD-437: Fixing respect CompileProcessTimeout in dotnet build step
* GD-446: Removed unused dependencies `Moq` and `CommandLineParser` from gdUnit4.api.
If your project relies on either, add them explicitly to your .csproj.
* GD-466: Fixing a failing Godot runtime exit is reported without a cause.
The runner now reports the exit code, the signal name of a crash (e.g. `SIGSEGV`, `SIGABRT`)
and the last 30 lines of the Godot error output, and states whether all test results were reported before.
The connection to Godot is now closed before the engine shuts down.
* GD-493: Fixing the Godot C# support check, which failed randomly on a slow Godot start
and skipped all tests that require the Godot runtime.
The check now reads the version of the Godot binary and also detects Godot builds without C# support.
* GD-492: Fixing the object deep equal comparison, which skipped a property when comparing its value threw an exception.
The exception now reaches the test, properties that cannot be read (indexers, throwing getters, ref struct values) are still skipped.
* GD-526: Fixing the stdout capture of a test, which lost the Godot output written right before the capture stops,
and on Windows kept reading after the capture stopped and took the output of a later capture.
* GD-528: Fixing the conversion of a `decimal` to a Godot `Variant`, which always failed, a `decimal` is now converted to a `float`.
* GD-532: Fixing the named pipe collision when the same test assembly runs in parallel, e.g. from two checkouts or CI jobs on one machine.
Each run now uses its own pipe to the Godot runtime.
✨ Improvements
* GD-311: Verify the Godot binary has C# support before running godot runtime tests to avoid invalid test execution.
If the binary not supports C#, all tests marked with [RequireGodotRuntime] will be skipped.
The logger now uses the prefix `[GdUnit4]` and additionally marks the output with a tag
- `:build:` for compilation tasks
- `:stdout:` for standard output messages.
- `:stderr:` for standard error messages
* GD-314: Allows the use of `OverrideFailureMessage` only at the beginning of the assertion chain to avoid errors.
```
AssertString("foo").OverrideFailureMessage("Custom failure message").IsEqual("bar"); // ✅
AssertString("foo").IsEqual("bar").OverrideFailureMessage("Custom failure message"); // ❌ Compile error
```
* GD-332: Do not allow returning null values on AutoFree to avoid spamming warnings
* GD-426: Add ambient LoggerFactory and LogCapture for testing
* GD-443: Make Godot runtime connect timeout configurable in ``.runsettings`
```
<!-- GdUnit4-specific configuration -->
<GdUnit4>
<GodotConnectTimeout>10000</GodotConnectTimeout>
</GdUnit4>
```
* GD-477: Add support of `PackedVector4Array` on Variant assertions, which failed before with a `NotImplementedException`
* GD-484: The package now targets `net8.0` and `net10.0` (C# 14) instead of `net8.0` and `net9.0`.
* GD-530: The test engine reports why tests were not executed, a crash of the Godot runtime with its exit code and signal or the test session timeout,
to the new `ITestEventListener.ReportNotExecutedCause`, which has a default implementation that ignores the cause.
The supported .NET versions are .NET 8 and .NET 10, projects targeting `net9.0` use the `net8.0` build.
* GD-485: Removed the `Microsoft.CodeAnalysis` and `Microsoft.CodeAnalysis.CSharp.Workspaces` dependencies, the async data point timeout now reads its source location from the debug symbols.
* GD-486: Replaced `Newtonsoft.Json` by `System.Text.Json` on the pipe to the Godot runtime, which now accepts only the known message types, the package no longer depends on `Newtonsoft.Json`.
* GD-511: Creating a test from the Godot editor supports methods and properties of structs, interfaces and records, of nested types
and of every type in a file with several types, the test suite is named after the type that contains the selected line.
v5.0.0
## Major Architecture Overhaul
**BREAKING CHANGES:**
* Test Engine Redesign: Complete rework of the test engine that no longer requires Godot runtime by default
* Migration Required: Tests using Godot features (scenes, nodes, resources) must now be marked with `[RequireGodotRuntime]` attribute
* Significant performance improvements for logic-only tests (up to 10x faster)
✨ New Features
GD-138: Add capture test case execution stdout to the test report by @MikeSchulze in #139
GD-144: Add AwaitInputProcessed to SceneRunner by @MikeSchulze in #145
GD-46: Added support of DataPoint attributes, which make it possible to define parameterized tests with dynamic test data by @MikeSchulze in #147
GD-153: Add Roslyn Analyzer to validate TestCase and DataPoint attribute combinations by @MikeSchulze in #154
GD-156: Add an exception hook to report exceptions as test failures that are caught by Godot by @MikeSchulze in #157
GD-160: Apply runsettings environment variables to the test execution context by @MikeSchulze in #161
GD-163: Collect the Godot log file into test report by @MikeSchulze in #164
GD-156: Install Godot exception handler and forward uncaught exceptions as test failure. by @MikeSchulze in #162
GD-682: Rework on GdUnit4Net API Godot bridge by @MikeSchulze in #197
GD-27: Add VSTest filter support with test categories and traits by @MikeSchulze in #201
GD-240: Add GDUNIT4NET_API_V5 Conditional Compilation Constant by @MikeSchulze in #241
Upgrade to .NET 8/9 with C# 12 support by @MikeSchulze in #267
GD-211: Implement missing AwaitSignalOn by @MikeSchulze in #282
🪲 Bug Fixes
GD-149: Add error to the execution log when the test session timeout occurs by @MikeSchulze in #150
GD-152: Fix test case display name for dynamic test data driven tests by @MikeSchulze in #176
Fixes Godot exception monitoring issues by @MikeSchulze in #187
Make WithTimeout public by @MikeSchulze in #189
GD-199: TestRunner install ends with abnormal exit on large projects by @MikeSchulze in #200
GD-203: Handle failure reporting for test stages [Before] and [After] by @MikeSchulze in #204
GD-212: Fix vector assertion IsEqualApprox by @MikeSchulze in #214
GD-284: Fix test failure causes the entire test execution if it is executed in the Godot Editor by @MikeSchulze in #285
🧹 Maintenance
GD-140: GdUnit4 API: code cleanup and formatting by @MikeSchulze in https://github.com/MikeSchulze/gdUni...
## 📋 Migration Guide:
**Before v5.0.0:**
```csharp
[Test]
public void MyTest()
{
// All tests ran in Godot runtime
var node = new Node();
AddChild(node);
}
```
**v5.0.0:**
```csharp
[Test]
public void MyLogicTest()
{
// Runs fast without Godot runtime
var result = Calculator.Add(1, 2);
AssertThat(result).IsEqual(3);
}
[Test]
[RequireGodotRuntime] // Required for Godot-dependent tests
public void MyGodotTest()
{
var node = new Node();
AddChild(node);
}
[Test]
[DataPoint(nameof(TestData))] // Data-driven tests
public void TestCalculations(int a, int b, int expected)
{
AssertThat(Calculator.Add(a, b)).IsEqual(expected);
}
[Test]
[ThrowsException(typeof(ArgumentNullException), "Value cannot be null")]
public void TestValidation()
{
Calculator.Add(null, 5); // Expects specific exception
}
public static IEnumerable<object[]> TestData => new[]
{
new object[] { 1, 2, 3 },
new object[] { 5, 7, 12 }
};
```
## ⚙️ Configuration:
New `.runsettings` options:
```xml
<RunSettings>
<GdUnit4>
<CaptureStdOut>true</CaptureStdOut>
<Parameters>--verbose --headless</Parameters>
<DisplayName>FullyQualifiedName</DisplayName>
<CompileProcessTimeout>30000</CompileProcessTimeout>
</GdUnit4>
</RunSett>
```
This release represents a major evolution in GdUnit4's architecture, providing developers with the flexibility to write fast, efficient tests while maintaining full Godot integration capabilities when required.
-------------------------------------------------------------------------------------------------------
v4.3.1
Bug Fixes:
* GD-135: Cannot test signals on non-node classes
-------------------------------------------------------------------------------------------------------
v4.3.0
Improvements:
* GD-127: Replace stdout based TestEventProcessor by IPC implementation
* GD-124: Use LaunchProcessWithDebuggerAttached instead of AttachDebuggerIfNeed for Rider 2024.2
-------------------------------------------------------------------------------------------------------
v4.2.5
Bug Fixes:
* GD-110: Allow a Node to be passed in to SceneRunner.Load as the root of the scene.
* GD-121: Improve AssertSignal by adding a StartMonitoring method
-------------------------------------------------------------------------------------------------------
V4.2.4
Improvements:
* GD-89: Add input action support to the `SceneRunner` by @MikeSchulze in https://github.com/MikeSchulze/gdUnit4Net/pull/92
- Added input action handling to the SceneRunner
- `SimulateActionPressed(string action)`
- `SimulateActionPress(string action)`
- `SimulateActionRelease(string action)`
* GD-94: Improve assertions error message when comparing objects by @MikeSchulze in https://github.com/MikeSchulze/gdUnit4Net/pull/95
* GD-99: Add support to load a scene by `uid://` path to the Scene Runner by @MikeSchulze in https://github.com/MikeSchulze/gdUnit4Net/pull/100
Bug Fixes:
* GD-90: Cleanup old runner configuration before run new tests by @MikeSchulze in https://github.com/MikeSchulze/gdUnit4Net/pull/93
* GD-96: Fix methods with a single parameterized test case are not executed by @MikeSchulze in https://github.com/MikeSchulze/gdUnit4Net/pull/97
* GD-101: Respect the GdUnit4 settings to notify about orphan nodes by @MikeSchulze in https://github.com/MikeSchulze/gdUnit4Net/pull/102
* GD-103: Trim MSTest assert stack trace by @MikeSchulze in https://github.com/MikeSchulze/gdUnit4Net/pull/105
* GD-104: Fix exception failure message propagation by @MikeSchulze in https://github.com/MikeSchulze/gdUnit4Net/pull/108
-------------------------------------------------------------------------------------------------------
v4.2.3
Bug Fixes:
- Fix `AssertThat` for dynamic assert type resolving
-------------------------------------------------------------------------------------------------------
v4.2.2
What's Changed:
- Rename repository from `gdUnit4Mono` to `gdUnit4Net`
- Update project to GodotSharp v4.1.0
- Format and fix warnings according to C# standards
- Format the tests according to the C# Formatting rules
- Format the code to C# standard
- Support both net7 and net8 at once
- Add full .NET8 support
- Provide generic vector assert to support all Godot vector types
- Revision of the stack trace collection for failed tests
- Complete missing features for `IDictionaryAssert`
- Complete missing features for `IEnumerableAssert`
- Complete missing features for `INumberAssert`
- Add missing `SimulateMouseMoveRelative` and `SimulateMouseMoveAbsolute` to `ISceneRunner`
Bug Fixes:
- SceneRunner: Fix InputEvent handling
- Calling Invoke on `SceneRunner` must propagate exceptions
- Fix GdUnit4MonoAPI `IsTestSuite` cannot run TestSuite
- Fix test run stops at some point
- Parameterized test cases are not run from Godot Editor GdUnit4 inspector
-------------------------------------------------------------------------------------------------------
v4.2.0
- gdUnit4 API initial version.