GdUnit4 C# Test Setup
With gdUnit4 version 4.2.2, we fully support .net7, .net8 and LangVersion 11.
This ensures compatibility and access to the enhanced features and capabilities provided by GdUnit4’s C# testing functionality.
Before diving into gdUnit4 C# testing API, make sure your project is configured appropriately.
Follow the steps outlined in the Official Godot documentary
GdUnit4 utilizes the C# language standard 11.0. To ensure seamless integration, adjust your project settings accordingly:
-
Setup your Project
gdUnit4Net C# API supports the frameworks net7.0 and net8.0 to support the latest language standard
Open you project file (*.csproj), and change:- under section
<PropertyGroup>
- change the TargetFramework to
net8.0
- add
<LangVersion>11.0</LangVersion>
- add
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
- change the TargetFramework to
- add the section
<ItemGroup>
see below
<ItemGroup> <PackageReference Include="gdUnit4.api" Version="4.2.*" /> </ItemGroup>
- under section
-
Ensure the dotnet 8 SDK is installed.
dotnet --list-sdks
7.0.404 [C:\Program Files\dotnet\sdk]
8.0.201 [C:\Program Files\dotnet\sdk]
If no sdk 8.0 installed, you can download it here
If you encounter issues with older SDKs, consider uninstalling them.
Here is a complete example of what your project should look like.
<Project Sdk="Godot.NET.Sdk/4.2.1">
<PropertyGroup>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>11.0</LangVersion>
<!--Force nullable warnings, you can disable if you want-->
<Nullable>enable</Nullable>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
<!--Disable warning of invalid/incompatible GodotSharp version-->
<NoWarn>NU1605</NoWarn>
</PropertyGroup>
<ItemGroup>
<!--Required for GdUnit4-->
<PackageReference Include="gdUnit4.api" Version="4.2.*" />
</ItemGroup>
</Project>
The GdUnit4 Godot Editor C# Support
To be able to use the GdUnit4 C# Test API, at least one Godot-Mono version 4.2.x must be installed.
GdUnit4 supports with gdUnit4.api v4.2.0 to write and run tests inside the Godot editor. For support Visual Studio, Visual Studio Code and JetBrains Rider click here.
Test You C# build Settings in the Godot Editor
Open the MSBuild inspector at the bottom of the Godot editor and press Rebuild Solution. The output should indicate that the project is built successfully.
Running C# Tests inside the Godot Editor
How to run test
Using External C# Editor
Open your Godot editor settings, and navigate to dotnet and select your preferred C# tool.