The gdUnit4 Test Adapter

The gdUnit4 Test Adapter, designed to facilitate the integration of GdUnit4 with test frameworks supporting the Visual Studio Test Platform VSTest.

The project repository can be found here gdunit4.test.adapter.

Supported IDE’s

IDE Test Discovery Test Run Test Debug Jump to Failure Solution test config file Test Filter Parallel Test Execution
Visual Studio 🔜
Visual Studio Code 🔜
JetBrains Rider version 2024.2 🔜

✅ - supported
☑️ - supported by a workaround (link)
❌ - not supported
🔜 - not yet implemented

Install

Install Nuget Packages and Project References

Add the following framework reference to your csproj:

    <ItemGroup>
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
        <PackageReference Include="gdUnit4.api" Version="4.3.*" />
        <PackageReference Include="gdUnit4.test.adapter" Version="2.*" />
    </ItemGroup>

Check the for latest version on nuget.org:

IDE’s

Preconditions

You need to setup the system environment variable GODOT_BIN, the full path to the Godot executable.

Platform Environment Variable Example Path
Windows %GODOT_BIN% d:\development\Godot_v4.2.1-stable_mono_win64\Godot_v4.2.1-stable_mono_win64.exe
Linux/Unix/Mac $GODOT_BIN /Users/MisterX/Documents/develop/GodotMono.app/Contents/MacOS/Godot

Or use the .runsettings to define the environment variable.

  <RunSettings>
    <RunConfiguration>
        <EnvironmentVariables>
            <GODOT_BIN>d:\development\Godot_v4.2.1-stable_mono_win64\Godot_v4.2.1-stable_mono_win64.exe</GODOT_BIN>
        </EnvironmentVariables>
    ...

Visual Studio

test-adapter

Do follow this steps to activate the test explorer:

  • Activate the test explorer explorer
  • Configure the path to your .runsettings explorer
  • Restart Visual Studio

Visual Studio Code

test-adapter

Do follow this steps to activate the test explorer:

  • Install the C# Dev Kit (v1.5.12 (pre-release) recommended). Detailed instructions can be found here. devkit
  • Open your .vscode/settings.json and add the following property to your project settings: It is important to use the correct C# Dev Kit version, which is currently a PreRelease. The property is newly introduced by this issue.

      "dotnet.unitTests.runSettingsPath": "./test/.runsettings"
    
  • Restart Visual Studio Code

JetBrains Rider

enable vstest

Do follow this steps to activate the test explorer:

Advice
We recommend to use Rider 2024.2 or higher to enable test debugging! Checkout for the latest version
For older Rider versions check the workaround.
  • Install the Godot Support plugin godot-support
  • [Optional] Configure the path to your .runsettings runsettings
  • Enable the VSTest adapters in the Rider settings enable vstest
  • Restart JetBrains Rider

Note: There is no need to set the GODOT_BIN for Rider.


The Test Adapter Settings

To configure the test execution, you can use a .runsettings file. Below is an example: The full guide to configure the settings can be found here.

<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
    <RunConfiguration>
        <MaxCpuCount>1</MaxCpuCount>
        <ResultsDirectory>./TestResults</ResultsDirectory>
        <TargetFrameworks>net7.0;net8.0</TargetFrameworks>
        <TestSessionTimeout>180000</TestSessionTimeout>
        <TreatNoTestsAsError>true</TreatNoTestsAsError>
        <EnvironmentVariables>
            <GODOT_BIN>d:\development\Godot_v4.2.1-stable_mono_win64\Godot_v4.2.1-stable_mono_win64.exe</GODOT_BIN>
        </EnvironmentVariables>
    </RunConfiguration>

    <LoggerRunSettings>
        <Loggers>
            <Logger friendlyName="console" enabled="True">
                <Configuration>
                    <Verbosity>detailed</Verbosity>
                </Configuration>
            </Logger>
            <Logger friendlyName="html" enabled="True">
                <Configuration>
                    <LogFileName>test-result.html</LogFileName>
                </Configuration>
            </Logger>
            <Logger friendlyName="trx" enabled="True">
                <Configuration>
                    <LogFileName>test-result.trx</LogFileName>
                </Configuration>
            </Logger>
        </Loggers>
    </LoggerRunSettings>

    <GdUnit4>
        <!-- Additional Godot runtime parameters-->
        <Parameters></Parameters>
        <!-- Controls the Display name attribute of the TestCase. Allowed values are SimpleName and FullyQualifiedName.
             This likely determines how the test names are displayed in the test results.-->
        <DisplayName>FullyQualifiedName</DisplayName>
    </GdUnit4>
</RunSettings>

Issues and Workarounds

Issue Solution
The test discovery is aborted and not all tests are found Increase the <TestSessionTimeout> in your RunSettings
Test Debug workaround for JetBrains Rider click here

Test Debug workaround for JetBrains Rider less version 2024.2

  • Paste this code into your test suite to wait until the debugger is connected to the Godot process.
    [BeforeTest]
    public void DebugWorkaround()
    {
        while (!Debugger.IsAttached)
        {
        }
    }
  • Set your breakpoints
  • Start debugging test
  • Attach the debugger to the running Godot instance. attach_debugger
  • Search for Godot and select and press attach select_process

document version v4.3.0


Copyright © 2021-2024 Mike Schulze. Distributed by an MIT license.