MikeSchulze / gdUnit4Net

A Godot C# Unit Test Framework.
MIT License
61 stars 5 forks source link

GD-152: Add Engine Mode for Test Cases #152

Open MikeSchulze opened 3 weeks ago

MikeSchulze commented 3 weeks ago

Is your feature request related to a problem? Please describe.

Currently, all tests in GdUnitNet are executed within the Godot engine, including unit tests that don't require engine functionality. This leads to unnecessary overhead and slower test execution for pure logic tests that could run independently of the engine.

Describe the solution you'd like

Introduce a way to explicitly mark which tests require the Godot engine runtime, allowing other tests to run more efficiently outside the engine context.

Option A: Extended TestCase Attribute

Add an engine parameter to the existing TestCase attribute:

[TestCase(engine = true)]
public async Task TestWithEngineComponents()
{
    var sceneRunner = ISceneRunner.Load("res://src/core/resources/scenes/TestSceneCSharp.tscn", true);
    await sceneRunner.SimulateFrames(100);
    // Test logic here
}

[TestCase] // or explicitly [TestCase(engine = false)]
public void TestPureLogic()
{
    // Pure C# logic testing
}

Pros:

Cons:

Option B: New GodotTestCase Attribute

Introduce a new attribute specifically for engine-dependent tests:

[GodotTestCase]
public async Task TestWithEngineComponents()
{
    var sceneRunner = ISceneRunner.Load("res://src/core/resources/scenes/TestSceneCSharp.tscn", true);
    await sceneRunner.SimulateFrames(100);
    // Test logic here
}

[TestCase]
public void TestPureLogic()
{
    // Pure C# logic testing
}

Pros:

Cons:

Error Handling

When a test uses Godot engine features without the appropriate attribute/flag:

Test should fail immediately with a clear error message Suggested error message: "This test uses Godot engine features but is not marked for engine execution. Please add [GodotTestCase] or [TestCase(engine = true)] to this test."

The framework should detect attempts to use engine features in non-engine tests, including: