This version of GdUnit4.api is based on Godot v4.4.stable.mono.official [4c311cbee] (master branch)
GdUnit4Net is a feature-complete unit testing framework for Godot C# projects that is fully compatible with the VSTest standard. It provides an API and VS test adapter to run your Godot C# tests seamlessly in Visual Studio (Code), JetBrains Rider, and any VSTest-compatible environment.
π High Performance: Up to 10x faster test execution for logic-only tests
π― VSTest Compatible: Full integration with Visual Studio Test Platform
β‘ Smart Runtime: Tests run without Godot runtime by default, with opt-in Godot features
π§ Feature Complete: All standard testing features you expect from modern frameworks
- Writing, executing and debugging tests with full IDE integration
- Wide range of assertion methods for verifying the behavior and output of your code
- Parameterized Tests (Test Cases and DataPoints) for testing functions with multiple sets of inputs and expected outputs
- Advanced Test Filtering with VSTest filter support, test categories, and traits
- Scene runner for simulating different kinds of inputs and actions, such as mouse clicks and keyboard inputs
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. - VSTest Adapter to run and debug your tests with full VSTest compatibility
- Powerful test filtering capabilities to selectively run tests based on various criteria
- Exception monitoring with automatic capture of Godot exceptions and runtime errors
- Test output capture including stdout and Godot log integration
- Roslyn Analyzers for compile-time validation of test attributes and combinations
- Flexible test execution - tests run without Godot runtime by default for maximum performance, with
[RequireGodotRuntime]
for Godot-specific features
GdUnit4Net v5.0 introduces a major architecture overhaul that revolutionizes test performance and compatibility:
- Smart Runtime Detection: Tests run in lightweight mode by default, only spinning up Godot runtime when explicitly needed
- Performance Boost: Logic-only tests execute up to 10x faster than previous versions
- VSTest Standard Compliance: Full compatibility with Visual Studio Test Platform and all VSTest features
- Selective Godot Integration: Use
[RequireGodotRuntime]
attribute only for tests that actually need Godot features
There are three packages available in this project:
- gdUnit4.api - The core package to enable writing and running unit tests in C#.
- gdUnit4.test.adapter - The test adapter to integrate GdUnit4 with Visual Studio Test Platform.
- gdUnit4.analyzers - A Roslyn-based analyzer that provides compile-time validation for GdUnit4 test attributes.
Checkout the gdUnit4.api README to install and use the core testing framework.
Checkout the gdUnit4.test.adapter README to install and use the test adapter. This adapter now supports powerful test filtering capabilities for selectively running tests based on specific criteria.
For compile-time validation of your test code, check out the gdUnit4.analyzers README.
This example project gives you a short insight into how to set up a Godot project to use the GdUnit4 API and test adapter. It demonstrates the new v5.0 features including selective Godot runtime usage and advanced testing capabilities.
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<object[]> TestData => new[]
{
new object[] { 1, 2, 3 },
new object[] { 5, 7, 12 },
new object[] { -1, 1, 0 }
};
}
}
Run tests with advanced filtering using VSTest standard syntax:
# 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)"
The test run looks like this:
- Up to 10x faster test execution for logic-only tests
- Tests run without Godot runtime by default
- Only use
[RequireGodotRuntime]
when you actually need Godot features
- Full compatibility with Visual Studio Test Platform
- Advanced test filtering with categories and traits
- Seamless integration with CI/CD pipelines
- DataPoint attributes for dynamic parameterized tests
- Exception monitoring with automatic Godot error capture
- Output capture including stdout and Godot logs
- Roslyn analyzers for compile-time validation
- Better error reporting and diagnostics
- Improved test discovery and execution
- Enhanced debugging capabilities
- Environment variable support from runsettings
Important: v5.0 includes breaking changes that require minimal code updates:
- Add
[RequireGodotRuntime]
to tests that use Godot features (Nodes, Scenes, Resources) - Remove unnecessary Godot dependencies from pure logic tests for better performance
- Update test filtering to use new VSTest-compatible syntax
- Give Feedback
- Suggest Improvements
- Report a Bug related to GdUnit4 API
- Report a Bug related to GdUnit4 Test Adapter
Thank you for your interest in contributing to GdUnit4!
To ensure a smooth and collaborative contribution process, please review our contribution guidelines before
getting started. These guidelines outline the standards and expectations we uphold in this project.
Code of Conduct: We strictly adhere to the Godot code of conduct in this project. As a contributor, it is important to respect and follow this code to maintain a positive and inclusive community.
Using GitHub Issues: We utilize GitHub issues for tracking feature requests and bug reports. If you have a general question or wish to engage in discussions, we recommend joining the GdUnit Discord Server for specific inquiries.
We value your input and appreciate your contributions to make GdUnit4 even better!
This project is licensed under the MIT License - see the LICENSE file for details.