MikeSchulze / gdUnit4Net

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

GD-131: Tests cannot report failure from within an exception handler #131

Closed zorbathut closed 4 months ago

zorbathut commented 4 months ago

The used GdUnit4 version

4.3.2 (Latest Release)

The used Godot version

v4.2.2 (custom)

Operating System

Manjaro Linux

Describe the bug

Because GdUnit4 uses unhandled exceptions to report failure, any failure that happens inside a universal exception handler never gets recognized.

Steps to Reproduce

Here is a test suite that fails in the appropriate way:

using GdUnit4;
using static GdUnit4.Assertions;

[TestSuite]
public class ExampleTest
{
    [TestCase]
    public void Failure()
    {
        AssertBool(false).IsTrue();
    }
}

Here is a test case that "succeeds", even though it shouldn't:

using System;
using GdUnit4;
using static GdUnit4.Assertions;

[TestSuite]
public class ExampleTest
{
    [TestCase]
    public void Failure()
    {
        try
        {
            AssertBool(false).IsTrue();
        }
        catch (Exception e)
        {

        }
    }
}

This makes it extremely difficult to test code inside exception handlers.

Minimal reproduction project

No response

MikeSchulze commented 4 months ago

Why you use a try catch block around the assertion? This is not common to use assertions, when you catch an exception without propagation the test will never fail. That is an expected behavior.