MikeSchulze / gdUnit4

A Godot Unit Test Framework. Support for GDScript and C# unit testing
MIT License
565 stars 30 forks source link

GD-571: Print statements appear neither in Output or GdUnitConsole #571

Closed adadgio closed 2 weeks ago

adadgio commented 2 weeks ago

The used GdUnit4 version

4.3.4 (Latest Release)

The used Godot version

v4.3

Operating System

Mac OS Sonoma

Describe the bug

In tests, the print() statement does not print anything in the Ouput tab nor in the GDUnit console. Not sure if this should be reporterd as or intended feature, but that would be very usefull nonetheless to debug tests.

Steps to Reproduce

Write any test and write a print("Anything you want") statement.

Minimal reproduction project

gdunitprintbugreport.zip

MikeSchulze commented 2 weeks ago

Hello, this is a Godot related issue, sometimes the console is not flashing the output. To avoid this, you need to add an await get_tree().process_frame after your print statement. e.g.

func test_do_something() -> void:
    # remove this line and complete your test
    print("Hello world")
    await get_tree().process_frame
    assert_that(1).is_equal(1)

You should also check your stdout settings image

The GdUnitConsole shows only test reports and no stdout statements.

Regards Mike

adadgio commented 2 weeks ago

Makes sense, works on successful tests assertions... Thanks!

adadgio commented 2 weeks ago

A have a question about mocking autoload singletons and methods, which I couldn't do despite the docs. Where you I ask about that ?

MikeSchulze commented 2 weeks ago

A have a question about mocking autoload singletons and methods, which I couldn't do despite the docs. Where you I ask about that ?

Mocking a autoload is not possible because autoloads are singletons and by default a single instance.

adadgio commented 2 weeks ago

Sorry, I meant stub a autoload method. Doing do_return on an autoloaded singleton is not possible ?

MikeSchulze commented 2 weeks ago

Sorry, I meant stub a autoload method. Doing do_return on an autoloaded singleton is not possible ?

Please do not ask not issue related questions here, please use the discussions or join the Discord server for direct help.

This is technical, not possible. The autoload instance is loaded by Godot and hold by a singleton instance. You can't build a mock/stub of this, this would need technical to replace the original instance and this is not possible.