Godot Unit Test. Unit testing tool for Godot Game Engine.
class_name
clauses to files:
extends GutTest
instead of extends 'res://addons/gut/test.gd'
when creating test scripts. That's 45% less text!extends GutHookScript
instead of using the path.InputFactory
static class to addons/gut/test.gd
to simplify creating InputEvent*
events for use in tests. See Input Factory.InputSender
class for mocking input and scripting input sequences. See Mock Input.func test_fireball_input():
var player = Fighter.new()
var sender = InputSender.new(player)
sender.action_down("down").hold_for(.1)\
.action_down("down_forward").hold_for(.1)\
.action_down("forward").key_down("FP")
yield(sender, 'idle')
assert_true(player.is_throwing_fireball())
"gut_on_top":true
).res://addons/gut
directory if you accidently include it as a test directory.New Gut Panel features: https://youtu.be/tWNswMIJHKk Mocking Input: https://youtu.be/cRKppa9R7ZQ
-gjunit_xml_file
and -gjunit_xml_timestamp
are supported on the command line.junit_xml_file
and junit_xml_timestamp
are supported in the .gutconfig.json
file.yield_frames
. It works similar to yield_for
except it will yield for N frames instead of N seconds.stub(...).param_count(x)
which allow you to specify the number of paramters a method has. Useful when working with vararg methods or NativeScripts. This addresses #246 and #252. See the Stubbing page in the wiki for more information.stub(...).param_defaults([])
which allows you to specify the default values that a method should get. See the Stubbing page in the wiki for more information.get_call_count
which allows you to get the number of times a method was called.assert_signal_emitted_with_parameters
is passed bad parameters.yield_to
now supports signals with up to 9 parameters. This is the same limit supported by watch_signals
.assert_is
no longer errors when asserting objects of type Reference
.assert_almost_eq
and assert_almost_ne
to work with Vectors properly.prerun_setup
, setup
, teardown
, postrun_teardown
deprecation warnings have been enabled. These were removed from the documentation over 2 years ago (6.6.0) and replaced with before_all
, before_each
, after_each
, and after_all
. Having to make additional changes for these in order to implement Issue 184 annoyed me, so there will now be depracation warnings for these. Earliest they could be removed is 8.0.0.assert_property
, assert_setget
, assert_setget_called
. You can now easily asssert you have your setget
properties setup correctly including ensuring that your setters/getters are used when accessing an attribute externally.assert_not_between
.assert_eq
and assert_ne
. It now lists up to 30 indexes that are different and thier values. Large arrays are also truncated when printed to cut down on output.compare_deep
, compare_shallow
, assert_eq/ne_deep
, assert_eq/ne_shallow
to aid in comparing dictionaries and arrays. See Comparing Things wiki page for more info.pass_test(text)
, fail_test(text)
, is_passing()
, is_failing()
methods to test.gd
.
assert_true(true, 'we got here')
! Long live pass_test('we got here')
!assert_called_with_paramters
now does a deep comparison of values instead of Godot's default equivalence check.assert_signal_emitted_with_parameters
now performs a deep compare of the paramters instead of Godot's default equivalence check.before_all
and after_all
are now formally supported. They will appear correctly in the output and asserts will be tracked in the summary.stub
the _init
method. Documentation has been updated.double
or partial_double
a GUT error is generated and null
is returned.stub
a GUT error is generated and nothing is stubbed.Error calling built-in function 'inst2dict': Not a script with an instance
when used in assertions.assert_true
and assert_false
now only accept boolean values. They will fail with anything else.assert_is
creates an orphan.before_all
will no longer be around for all tests.gut_ready
should be used instead of _ready
when performing any actions on the GUT object in your test runner scene. You should avoid interacting with GUT until this signal has been emitted.gut.p
no longer supports the 3rd optional parameter for indent level. The parameter still exists but does nothing and generates a deprecation warning.assert_no_new_orphans
autofree
, autoqfree
, add_child_autofree
, add_child_autoqfree
.[Node:1234](my_script.gd)
now instead of just [Node:1234]
. Types are also included where appropriate. For example Color(1,1,1,1)
instead of (1,1,1,1)
but strings and numbers aren't changed.File
. These are now detected and handled.assert_almost_eq
no longer breaks all the beautiful colors in the display..txt
extension instead of .gd
. This was causing issues with warnings and exporting tests. If you want to export your tests you must now include *.txt
files. A warning was added if the templates are missing.assert_connected
and assert_not_connected
which allow you to assert an object is connected to a signal.assert_typeof
and assert_not_typeof
.ERROR: get_as_ratio: Cannot get ratio when minimum and maximum value are equal.
due to changes in 3.2. These have been corrected.assert_freed
and assert_not_freed
methods.get_stack
magic.Node2D
and Raycast2D
. Syntax is the same.pre
and post
run script hooks that allow you to run your own code before any tests are run and after all tests are run. This can be useful in setting global values before a run or investigating the results of the run for CICD pipelines and the like. Check the wiki for more info
ignore_method_when_doubling
was added as a workaround for doubling scripts that have static methods. The Doubles wiki page has more info about this method.attempt to disconnect signal...while emitting
can occur. Disconnecting from signals is now done via call_deferred
.to_call_super
so that you can force a doubled object to call its super method instead of being stubbed out.to_do_nothing
. This allows you to be a little more deliberate in your stubbing and is more readable than to_return(null)
which is basically all it does. It also suppresses un-stubbed method messages.partial_double
method. This will give you an object that has all of its methods stubbed to_call_super
. So it will act the same as a normal object, but you can spy and stub methods on it as well.to_call_super
under the covers. This means you can stub methods you haven't overloaded in your class (before you could only spy on them).-gexit_on_success
option to the command line to only exit if all tests passed.get_version
method to Gut.gd
.WindowDialog
to a Control
)log
option in the .gutconfig.json
file has changed to log_level
for consistency.get_call_parameters
which allows you to get the parameters sent to a call to a doubled method. It returns the most recent call by default but you can specify an optional index as well.replace_node
which allows you to replace a node in a scene with another node by specifying the node path. This makes testing scenes that use the $
syntax to get a reference to a child node easier to test by giving you a quick way to inject a double of any child node. The node that was replaced is freed with queue_free
-gprint_gutconfig_sample
command line option will print you a full config file that you can start using.log
option in the .gutconfig changed to log_level
.add_script
. If you pass a 2nd parameter an error is generated, but everything will continue to run.end_test
and the old gut.end_yielded_test
. These no longer need to be called.assert_get_set_methods
was replaced with assert_accessors
awhile ago. In this release I added deprecation messages for this method. It still works, but wanted to start getting the message out.assert_extends
has been replaced with assert_is
to match the 3.0 names.Missed a new directory in the .gitattributes.