Godot Unit Test. Unit testing tool for Godot Game Engine.

Gut 7.2.0

GUT (Godot Unit Test) is a unit testing framework for the Godot Engine. It allows you to write tests for your gdscript in gdscript.

Donate/Shameless Plug

If you would like to help support GUT check out my game Country or State on Android and iOS. Then, purchase the full version even if you don't like it. Thanks!

Features

More info can be found in the wiki.

Getting Started

VSCode Extension

Run your tests directly from the VSCode Editor. Search VSCode extensions for "gut-extension". The plugin has commands to run your entire test suite, a single test script or a single test.

License

Gut is provided under the MIT license. License is in addons/gut/LICENSE.md

Tutorials

Owner
Comments
  • Speeding up GUT main scene

    Speeding up GUT main scene

    When I launch my TestMain.tscn (which is just an instance of the GUT GUI runner), Godot takes a long time to load - sometimes around ten seconds - presumably while it discovers all the tests.

    In terms of "data shape," I have:

    • 40 test classes
    • 20 (nested) directories and subdirectories
    • Every test uses preload to load stuff

    Is there anything I can try to speed this up? Maybe switching from preload to load?

  • Setting a big project default font makes GUT unusable

    Setting a big project default font makes GUT unusable

    If I set a large default font on my project theme (for accessibility reasons), the GUT UI becomes huge and it's difficult/impossible to use (can't select a particular test suite). If I apply a new theme to the Gut control, it looks OK in the editor, but doesn't apply in-game. (This is Godot 3.2.3.)

    image

    image

  • Command line version doesn't load singletons

    Command line version doesn't load singletons

    So the same test may pass when called from scene and fail to run (it just shows the testing window and keeps counting time, without reporting failure or quitting) when called from command line script.

  • Closes #70: implemented new assert to check if a property uses setget keyword

    Closes #70: implemented new assert to check if a property uses setget keyword

    • Added test resources;
    • Added inner test classes for new assert functions to test_test.gd;
    • Added assert_setget_called, assert_setget, assert_property and three helper functions to test.gd
    • Added readme samples

    Wiki description: I will create a second PR against the wiki to add the wiki description and examples for new asserts => If that fails i can add them here later.

    questions:

    • There is two helper functions to retrieve a class from an object and vise versa. I added them to the test.gd script because I use them over there but I feel they might be better part of the utils.gd script. What do you think?
    • There is an issue with the gut internal timers when gut is setup in the unit tests (test_test.gd). You can see my comment in the before_each methods of the inner test classes for the new asserts. => I do not want the code from before_each to be merged but I'd like to hear your opinion on how to handle this. (And sorry for being rude accessing internal gut attributes...) => My suggestion would be to create a separate issue for that and resolve it over there.

    Test runs: At the end of this PR I will add the summaries of test run on the current masters code ("before changes from this PR") and test run after making the changes. As you will see, I didn't started with zero failed tests but I also didn't create new ones. For the orphans I created three new ones => according to #204 this is correct.

    ----- summary test run before changes from this PR: Totals Scripts: 31 Tests: 668 Passing asserts: 875 Failing asserts: 19 Pending: 4

    Warnings/Errors:

    • 13 Errors.
    • 13 Warnings.
    • 6 Deprecated calls.

    875 passed 19 failed. Tests finished in 46.9s

    [Orphans]: 6242 new orphans(total). Note: This count does not include GUT objects that will be freed upon exit. It also does not include any orphans created by global scripts loaded before tests were ran. Total orphans = 6338

    ----- summary test run after changes from this PR: Totals Scripts: 31 Tests: 694 Passing asserts: 906 Failing asserts: 19 Pending: 4

    Warnings/Errors:

    • 13 Errors.
    • 13 Warnings.
    • 6 Deprecated calls.

    906 passed 19 failed. Tests finished in 47.3s

    [Orphans]: 6242 new orphans(total). Note: This count does not include GUT objects that will be freed upon exit. It also does not include any orphans created by global scripts loaded before tests were ran. Total orphans = 6341

  • Stubbing Input Class

    Stubbing Input Class

    Is there any way to stub the return values of the Input class? e.g Input.is_action_just_pressed

    In the example tutorials it seems like they were just not tested. Is it not possible or should it just not be tested?

  • Cannot find test path in export

    Cannot find test path in export

    Hello there !

    I'm trying to export a project with gut as main scene, in order to be able to test godot-jvm feature on all platforms. I followed this documentation, to export this project.

    I set script as text:
    image

    When I try to run the export, I got this:
    image

    I checked with pck unpacker, and scripts are there in text format.

    Do you have any clue about what I'm doing wrong ?

  • Cannot stub Engine classes

    Cannot stub Engine classes

    Hi,

    Great framework, I'm a bit new and I think I've either ran into a current limitation or a misunderstanding my my part. I currently cannot seem to mock out Engine objects, for example RayCast2D objects.

    In this example, I'd like to stub out calls to topRay.get_collider(), to return a physics body I provide in the test.

    When I do so I get the error Invalid get index '_gut_metadata_(on base: 'RayCast2D').`

    extends "res://addons/gut/test.gd"
    
    var enemyCollisionBehavior
    
    func before_each():
    	enemyCollisionBehavior = load(
    		"res://Prefabs/Characters/Behaviors/EnemyCollisionBehavior.tscn").instance()
    
    func test_objectOnTop():
    	var body = Node.new()
    	
    	var topRay = RayCast2D.new()
    	stub(topRay, 'get_collider').to_return(body)
    

    Any ideas on what I could be doing wrong or can we only mock/stub out custom implementations?

  • Feature request: partial doubles

    Feature request: partial doubles

    I come from a C# background. We use Moq a lot for mocks/doubles. It allows you to create partial mocks as well, meaning: create a mock/double of this class, retaining all functionality except what you explicitly override.

    I would like to use this in Gut also; although, currently, I can probably use a work-around like breaking a function into smaller pieces and just testing those instead.

    Partial mocks might look something like this:

    double partial_mocked = double("res://scripts/Monster.gd").new().partial_mock()
    stub(partial_mocked, "expensive_calculation").to_return(17)
    var actual = partial_mocked.secret_value() # calls expensive_calculation and doubles it
    assert_eq(34, actual)
    

    In my case, I have a wrapper function that calls a second function, which I want to stub out; I don't want to stub out the entire instance.

  • Command line segmentation fault on closing test window

    Command line segmentation fault on closing test window

    GUT version: 6.6.0 Godot version: 3.1 alpha+ Platform: Windows 10

    I use git pre-commit hook to run tests as some sort of CI, and git won't allow me to go past this point, even if all tests passed (after closing a window):

    .git/hooks/pre-commit: line 9:  3604 Segmentation fault      godot -d -s addons/gut/gut_cmdln.gd
    

    I think #84 might cause this error that I've stumbled upon several times, but can't seem to reproduce it (or actually can't isolate the problem).

    My hook looks like this:

    #!/bin/sh
    
    # Run tests
    godot -d -s addons/gut/gut_cmdln.gd
    

    I'll report more info when I can pinpoint the problem.

  • Option to disable Debug Console

    Option to disable Debug Console

    The debug console is a handy feature when I am using GUT from my computer. But when I have GUT being run as part of CI, it hangs the runner. I would like to have an option to have the debugger just exit with an error and print the line of the error and reason.

  • Improve viewing results at a glance

    Improve viewing results at a glance

    The idea here is to make it easy to quickly see which files / tests failed in the UI, without having to scroll through and squint at the console text. I sometimes work on a small monitor, and with the right-side settings bar not being collapsable, I can get pretty heavy wordwrapping that makes it hard to read tests outputs at a glance. Even with a wider screen, you still have to focus to follow the indention to see where failures are. To be clear, I'm not saying that should change, it's a console output afterall, but I would think it would be helpful to have a way to more quickly glance at what went wrong. Some aspects of this request could be similar or related to https://github.com/bitwes/Gut/issues/340, but I think they are complementary:

    • The request here is more to do with creating additional interface hierarchy to complement the detailed console output
    • #340 could partially improve this request if the test filenames and test names themselves were color highlighted, but I still have to scroll to through a window with "all the detail" to see only the summary.
    • If an interface is created around quick viewing which tests failed, it could tie in to the way you jump into those specific files, versus make the console out somehow a clickable experience.

    The above description is intentionally vague about the precise user experience as I think it could be accomplished in a number of ways, some more subtle and simple, but some ideas:

    • Simplest: Hover over or click the Passing ## | Failing ## sections to see just a dropdown or window that shows which test files+test names failed (or passed, if you hover over that one); maybe this is a modal popup since some people could have a huge number of entries. No interaction other than listing the names, though this popup could tie into #340.
    • Hierarchy dropdown navigation of the tests themselves. I don't love this experience (this doesn't show "results", pretend it does), but there is some nugget of usefulness perhaps. It would also enable easy reruns of specific tests/files right from the panel, without having to jump in and open the specific test file and place your cursor to get the quick "Current: run" button (a feature, btw, I absolutely love)
    • Most complex: Introduction of a tab system, split into "Results", "Console", "Settings" (you're typically only looking at one of these at once anyways, right?). "Results" or perhaps "Summary" here would be more of an interface wrapped around the raw console/internal structure. Consider an analogy of a structured json file where all fields and subfields start off in a collapsed state so you can view at a high level quickly and expand where you want. This also lends itself to future interactively without having to mess with the console output (I'd hope the console output in Godot stays exactly the same to my command prompt/terminal console out, so I can confidently use GUT with or without a UI with the same experience).

    Sorry if I missed any similar proposals, I did a quick look and didn't find any.

  • [Bug] default function parameters set to null when partial_doubling

    [Bug] default function parameters set to null when partial_doubling

    Similar to #436 default values of function doubles do not get properly doubled, leading to undesired behaviour and failing tests. current workaround is to not double a class and use a separate inner class in the test script to differentiate functions.

    # i_have_defaults.gd
    extends Object
    class_name IHaveDefaults
    
    func defaults(i: int, j: int=25) -> int:
        return i*j
    
    # test_defaults.gd
    extends GutTest
    
    var IHaveDefaults = load("res://test/unit/i_have_defaults.gd")
    
    func test_defaults_partial_double():
        var cls = autoqfree(partial_double(IHaveDefaults).new())
        assert_eq(cls.defaults(2, 25), 50)
        assert_eq(cls.defaults(2), 50) #throws script error j is null
    
    func test_defaults_og():
        var cls=autofree(IHaveDefaults.new())
        assert_eq(cls.defaults(2, 25), 50)
        assert_eq(cls.defaults(2), 50) # fine
    

    output:

    res://test/unit/test_bug.gd
    * test_defaults_og
    * test_defaults_partial_double
    SCRIPT ERROR: Invalid type in function 'defaults'. Cannot convert argument 2 from Nil to int.
              at: defaults (<built-in>:63)
        [Failed]:  [Null] expected to equal [50]:  
          at line -1
    3/4 passed.
    
  • Gut does not stop internal timer after callback.

    Gut does not stop internal timer after callback.

    In some complex setups GUT it is possible to cause GUT to yield for less time than it is supposed to. _yielding_callback should call _yield_timer.stop().

  • [Godot 4] [ParseError] in res://addons/gut/gui/RunAtCursor.gd

    [Godot 4] [ParseError] in res://addons/gut/gui/RunAtCursor.gd

    res://addons/gut/gui/RunAtCursor.gd:111 - Invalid set index 'hint_tooltip' (on base: 'Button') with value of type 'String'.

    https://github.com/bitwes/Gut/blob/5f18bb972677c0368993d9fcb54db7e25c367810/addons/gut/gui/RunAtCursor.gd#L111

    I do not know how to resolve this. But if you explain me, I can make a PR :) !

  • [Godot 4] [ParseError] in res://addons/gut/gui/GutBottomPanel.gd

    [Godot 4] [ParseError] in res://addons/gut/gui/GutBottomPanel.gd

    Invalid call. Nonexistent function 'new' in base 'GDScript'.

    https://github.com/bitwes/Gut/blob/5f18bb972677c0368993d9fcb54db7e25c367810/addons/gut/gui/GutBottomPanel.gd#L57

    I do not know how to resolve this. But if you explain me, I can make a PR :) !

  • [Godot4] [ParseError] in res://addons/gut/gui/gut_config_gui.gd

    [Godot4] [ParseError] in res://addons/gut/gui/gut_config_gui.gd

    Parse Error: Cannot call non-static function "dir_exists()" on the class "DirAccess" directly. Make an instance instead.

    https://github.com/bitwes/Gut/blob/5f18bb972677c0368993d9fcb54db7e25c367810/addons/gut/gui/gut_config_gui.gd#L276

    Is path absolute ? If yes you can use DirAccess.dir_exists_absolute(path)

    Can I make a PR ?

This repository includes consumer driven contract test for provider, unit test and counter api.

This repository includes consumer driven contract test for provider, unit test and counter api.

Feb 1, 2022
Arkanoid game in Go using Ebiten game engine with ECS.
Arkanoid game in Go using Ebiten game engine with ECS.

Arkanoid-go Arkanoid game in Go using Ebiten game engine with ECS. You must have Git LFS installed when cloning the repository to download assets. See

Oct 9, 2022
AircraftWar - a game powered by Go+ spx game engine
AircraftWar - a game powered by Go+ spx game engine

AircraftWar - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download thi

Jan 5, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
FlappyCalf - a game powered by Go+ spx game engine
FlappyCalf - a game powered by Go+ spx game engine

FlappyCalf - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this

Nov 6, 2022
MazePlay - a game powered by Go+ spx game engine
MazePlay - a game powered by Go+ spx game engine

MazePlay - a game powered by Go+ spx game engine How to run Download Go+ and build it. See https://github.com/goplus/gop#how-to-build. Download this g

Dec 16, 2021
A Golang tool that does static analysis, unit testing, code review and generate code quality report.
A Golang tool that does static analysis, unit testing, code review and generate code quality report.

goreporter A Golang tool that does static analysis, unit testing, code review and generate code quality report. This is a tool that concurrently runs

Jan 8, 2023
Kakoune syntax highlighting for the Godot Engine / Godot Scripting Language gdscript
Kakoune syntax highlighting for the Godot Engine / Godot Scripting Language gdscript

gdscript-kak Kakoune syntax highlighting for the Godot Engine / Godot Scripting Language gdscript. Adds basic syntax highlighting to your .gd files fo

Mar 2, 2021
Easier way to unit test terraform

Unit testing terraform (WIP) Disclaimer Currently, the only way to compare values is using JSON query path and all types are strings. want := terraf

Aug 16, 2022
A simple yet intuitive golang unit test framework.

gotest Intuitive and simple golang testing framework which helps in writing unit tests in a way which improves the readability of the test. Here is an

Jan 1, 2022
Benchmarking deferent Fibonacci functions and algorithms with running unit test

GoFibonacciBench Benchmarking deferent Fibonacci functions and algorithms with running unit test ... Introduction: Fibonacci numbers are special kinds

Feb 27, 2022
Belajar golang unit test

perintah eksekusi di root folder : go test -v ./... assertion ambil dari framewo

Feb 3, 2022
go websocket client for unit testing of a websocket handler

wstest A websocket client for unit-testing a websocket server The gorilla organization provides full featured websocket implementation that the standa

Dec 21, 2022
Demo project for unit testing presentation @ GoJKT meetup

go-demo-service Demo project for unit testing presentation @ GoJKT meetup This is a demo project to show examples of unit testing for GoJKT meetup Use

Jul 10, 2021
A mock of Go's net package for unit/integration testing

netmock: Simulate Go network connections netmock is a Go package for simulating net connections, including delays and disconnects. This is work in pro

Oct 27, 2021
An example repo for RESTful API with swagger docs & unit testing

go REST API An example repo for RESTful API with swagger docs & unit testing Starting development server Copy .env.example to .env in the same directo

Nov 5, 2021
Go Unit Testing Clean Arch

Golang Unit Testing Tutorial melakukan unit testing di Golang yang sudah menerapkan clean architecture Menjalankan Service PSQL_HOST=<IP Database Serv

Feb 12, 2022
A basic module for understanding functions, error handling, arrays, maps, unit testing, and compiling

Learning Go Basics Concepts A basic module for understanding functions, error handling, arrays, maps, unit testing, and compiling go mod init download

Dec 15, 2021
Vault mock - Mock of Hashicorp Vault used for unit testing

vault_mock Mock of Hashicorp Vault used for unit testing Notice This is a person

Jan 19, 2022