Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
MikeSchulze opened this issue Nov 2, 2024 · 0 comments · Fixed by #165
Open

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

MikeSchulze opened this issue Nov 2, 2024 · 0 comments · Fixed by #165
Assignees
Labels
enhancement New feature or request gdunit4.api Issue is related to the `gdunit4.api`
Milestone

Comments

@MikeSchulze
Copy link
Owner

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:

  • No breaking changes to existing tests
  • Clear and explicit opt-in for engine-required tests
  • Consistent with existing attribute structure

Cons:

  • Additional parameter might be overlooked
  • Default value needs careful consideration

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:

  • Very clear distinction between test types
  • No ambiguity about test requirements
  • Follows Single Responsibility Principle

Cons:

  • Breaking change requiring migration of existing tests
  • Additional attribute to maintain

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:

  • Node operations
  • Scene management
  • Physics interactions
  • Input system usage
  • Signal connections
  • Resource loading
@MikeSchulze MikeSchulze added enhancement New feature or request gdunit4.api Issue is related to the `gdunit4.api` labels Nov 2, 2024
@MikeSchulze MikeSchulze self-assigned this Nov 2, 2024
@MikeSchulze MikeSchulze changed the title Add Engine Mode for Test Cases GD-152: Add Engine Mode for Test Cases Nov 2, 2024
@MikeSchulze MikeSchulze added this to the 4.4.0 milestone Nov 26, 2024
@MikeSchulze MikeSchulze reopened this Nov 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request gdunit4.api Issue is related to the `gdunit4.api`
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant