AutoworkTest๏
Experimental: Some methods may not be implemented and may be changed in future versions.
Test base class for the built-in unit testing framework.
Description๏
The AutoworkTest class is the base class for defining unit tests in the Autowork framework.
Tests are typically implemented by extending this class and defining test methods that contain assertions.
The framework automatically discovers and executes these methods based on naming conventions and configuration rules provided by AutoworkCollector and AutoworkConfig.
Tutorials๏
Methods๏
Signals๏
frameout() ๐
Signal used by wait_process_frames() and wait_physics_frames().
timeout(return_value: bool) ๐
Signal used by wait_while(), wait_until() and wait_for_signal().
Enumerations๏
enum SimulateMethod: ๐
SimulateMethod SIMULATE_BOTH = 0
Call both Node._process() and Node._physics_process().
See simulate().
SimulateMethod SIMULATE_PROCESS = 1
Call only Node._process().
See simulate().
SimulateMethod SIMULATE_PHYSICS = 2
Call only Node._physics_process().
See simulate().
Method Descriptions๏
void _after_all() virtual ๐
Method called after all tests.
void _after_each() virtual ๐
Method called after each test.
void _before_all() virtual ๐
Method called before all tests.
void _before_each() virtual ๐
Method called before each test.
Node add_child_autofree(child: Node) ๐
Adds a child node to the test sandbox and schedules it for automatic deletion at the end of the test.
Node add_child_autoqfree(child: Node) ๐
Adds a child node to the test sandbox and schedules it for automatic deletion at the end of the test.
bool assert_accessors(object: Object, property: StringName, default: Variant, set_to: Variant) ๐
Asserts that the property of object has a getter method that returns default by
default and a setter method that correctly updates the property.
The assertion calls the setter with set_to and then verifies that the getter returns the new value.
assert_accessors(player, "position", Vector2.ZERO, Vector2(200, 200))
bool assert_almost_eq(got: Variant, expected: Variant, error_margin: Variant, text: String = "") ๐
Asserts that got is equal to expected within a margin of error defined by error_margin.
assert_almost_eq(1.05, 1.0, 0.1, "The value is inside of the range [0.9, 1.1]")
bool assert_almost_ne(got: Variant, expected: Variant, error_margin: Variant, text: String = "") ๐
Asserts that got is not equal to expected within a margin of error defined by error_margin.
assert_almost_ne(0.5, 1.0, 0.1, "The value is outside of the range [0.9, 1.1]")
bool assert_between(got: Variant, expect_low: Variant, expect_high: Variant, text: String = "") ๐
Asserts that got is between expect_low and expect_high.
assert_between(5, 1, 10, "5 is between 1 and 10")
bool assert_called(object: Object, method: StringName, args: Array = [], text: String = "") ๐
Asserts that a method was called on a stubbed or spied object.
assert_called(obj, "call_me_maybe", [1, 2])
bool assert_called_count(object: Object, method: StringName, expected_count: int, args: Array = [], text: String = "") ๐
Asserts the spied method was called the expected number of times.
assert_call_count(child_node, "get_parent", 1, [], "get_parent called once")
bool assert_connected(source: Object, target: Object, signal: StringName, method_name: StringName = "") ๐
Asserts that the signal from source is connected to method_name from target.
bool assert_dir_does_not_exist(dir_path: String, text: String = "") ๐
Asserts that a directory at dir_path does not exist.
assert_dir_does_not_exist("res://void.txt")
bool assert_dir_exists(dir_path: String, text: String = "") ๐
Asserts that a directory at dir_path does exist.
assert_dir_exists("res://scripts/player.gd")
bool assert_does_not_have(variant: Variant, element: Variant, text: String = "") ๐
Asserts that variant does not have the specified element.
Note: only types of Array, Dictionary and String are supported.
assert_does_not_have({"a": 1, "b": 2}, "c", "Dict does not have key c")
bool assert_eq(got: Variant, expected: Variant, text: String = "") ๐
Asserts that expected is equal to got.
assert_eq(2 + 2, 4, "2 + 2 is equal to 4")
bool assert_eq_deep(got: Variant, expected: Variant, text: String = "") ๐
This is similar to assert_eq().
When this assert fails with Array or Dictionary as parameters, it will log the difference between the params.
bool assert_exports(object: Object, property: StringName, type: Variant.Type) ๐
Asserts that object exports a property with the name property and a type of type.
bool assert_false(condition: bool, text: String = "") ๐
Asserts that condition is false.
bool assert_file_does_not_exist(file_path: String, text: String = "") ๐
Asserts a file does not exist at the specified file_path.
assert_file_does_not_exist("res://this_does_not_exist.txt")
bool assert_file_empty(file_path: String, text: String = "") ๐
Asserts the specified file at file_path is empty.
bool assert_file_exists(file_path: String, text: String = "") ๐
Asserts a file exist at the specified file_path.
assert_file__exist("res://scripts/player.gd")
bool assert_file_not_empty(file_path: String, text: String = "") ๐
Asserts the specified file at file_path is not empty.
bool assert_freed(object: Object, text: String = "") ๐
Asserts that the object has been freed.
bool assert_ge(got: Variant, expected: Variant, text: String = "") ๐
Asserts got is greater than or equal to expected.
bool assert_gt(got: Variant, expected: Variant, text: String = "") ๐
Asserts got is greater than expected.
bool assert_gte(got: Variant, expected: Variant, text: String = "") ๐
Alias of assert_ge().
bool assert_has(variant: Variant, element: Variant, text: String = "") ๐
Asserts that variant has the specified element.
Note: only types of Array, Dictionary and String are supported.
assert_has([1, 2, 3], 2, "Array has 2")
bool assert_has_method(object: Object, method: StringName, text: String = "") ๐
Asserts that the object has method.
assert_has_method(self, "_ready")
bool assert_has_signal(object: Object, signal: StringName, message: String = "") ๐
Asserts that the object has signal.
assert_has_signal(node2d, "draw", "Node2D has 'draw' signal")
bool assert_is(object: Object, class: String, text: String = "") ๐
Asserts that object extends class.
assert_is(player, "CharacterBody2D", "player is a CharacterBody2D")
bool assert_le(got: Variant, expected: Variant, text: String = "") ๐
Asserts got is less than or equal to expected.
bool assert_lt(got: Variant, expected: Variant, text: String = "") ๐
Asserts got is less than expected.
bool assert_lte(got: Variant, expected: Variant, text: String = "") ๐
Alias of assert_le().
bool assert_ne(got: Variant, expected: Variant, text: String = "") ๐
Asserts that got is not equal to expected.
assert_ne("hello", "world")
bool assert_ne_deep(got: Variant, expected: Variant, text: String = "") ๐
This is similar to assert_eq().
When this assert fails with Array or Dictionary as parameters, it will log the difference between the params.
bool assert_no_new_orphans(message: String = "") ๐
Asserts that no new orphaned instances were created since the test began.
bool assert_not_between(got: Variant, expect_low: Variant, expect_high: Variant, text: String = "") ๐
Asserts that got is not between expect_low and expect_high.
assert_not_between(5, 1, 10, "15 is not between 1 and 10")
bool assert_not_called(object: Object, method: StringName, args: Array = [], text: String = "") ๐
Asserts that a method was not called on a stubbed or spied object.
assert_not_called(obj, "get_name")
bool assert_not_connected(source: Object, target: Object, signal: StringName, method_name: StringName = "") ๐
Asserts that the signal from source is not connected to method_name from target.
assert_not_connected(base, self, "child_exiting_tree", "fail_test")
bool assert_not_freed(object: Object, text: String = "") ๐
Asserts that the object has not been freed.
bool assert_not_null(got: Variant, text: String = "") ๐
Asserts that got is not null.
bool assert_not_same(got: Variant, expected: Variant, text: String = "") ๐
Asserts got and expected are not the same.
bool assert_not_typeof(variant: Variant, type: Variant.Type, text: String = "") ๐
Asserts that the type of variant is not type.
assert_not_typeof("5", TYPE_INT)
bool assert_null(got: Variant, text: String = "") ๐
Asserts that got is null.
bool assert_property(object: Object, property: String, default: Variant, set_to: Variant) ๐
Asserts that the object has a setter and getter methods for the property.
It will then use the getter to check if default is returned.
Then use the setter with set_to and verify the getter returns the same value.
assert_property(player, "position", Vector2(0, 0), Vector2(100, 100))
bool assert_property_with_backing_variable(object: Object, property: String, default_value: Variant, new_value: Variant, backed_by_name: String = "") ๐
Assumes backing variable will be _[param property].
This will perform all the asserts of assert_property().
Then this will set the value through the setter and check the backing variable value.
It will then reset through the setter and set the backing variable and check the getter.
bool assert_readonly_property(object: Object, property: String, new_value: Variant, expected: Variant, text: String = "") ๐
Asserts the property is readonly by trying set it to new_value and then
checking if the value is the same as expected.
bool assert_same(got: Variant, expected: Variant, text: String = "") ๐
Asserts got and expected are the same.
bool assert_set_property(object: Object, property: String, new_value: Variant, expected: Variant, text: String = "") ๐
Sets the property of object to new_value,
then checks if the property is set to expected.
var a = 0:
set(new_value):
a = new_value + 2
assert_set_property(self, "a", 2, 4)
bool assert_signal_emit_count(object: Object, signal: StringName, expected_count: int, message: String = "") ๐
Asserts that signal was fired expected_count times from object.
assert_signal_emit_count(node, "draw", 2, "Signal 'draw' was emitted twice")
bool assert_signal_emitted(object: Object, signal: StringName, message: String = "") ๐
Asserts that signal was emitted by object.
assert_signal_emitted(player, "dead", "the player is dead")
bool assert_signal_emitted_with_parameters(object: Object, signal: StringName, expected_parameters: Array, index: int = -1, message: String = "") ๐
Asserts that signal was emitted by object with expected_parameters.
An optional index can be passed when a signal has fired more than once.
The default is to retrieve the most recent emission of the signal.
assert_signal_emitted_with_parameters(node, "child_entered_tree", [node], 0, "Signal parameters matched")
bool assert_signal_not_emitted(object: Object, signal: StringName, message: String = "") ๐
Asserts that signal was not emitted by object.
bool assert_string_contains(got: String, expected: String, text: String = "") ๐
Assert that the String got contains expected.
assert_string_contains("Hello, World!", "World")
bool assert_string_ends_with(got: String, expected: String, text: String = "") ๐
Assert that the String got ends with expected.
assert_string_ends_with("Hello, World!", "!")
bool assert_string_starts_with(got: String, expected: String, text: String = "") ๐
Assert that the String got starts with expected.
assert_string_starts_with("Hello, World!", "H")
bool assert_true(condition: bool, text: String = "") ๐
Asserts that condition is true.
bool assert_typeof(variant: Variant, type: Variant.Type, text: String = "") ๐
Asserts that the type of variant is type.
assert_typeof(5, TYPE_INT)
void autofree(object: Object) ๐
Marks object to be freed after the test finishes.
void autoqfree(node: Node) ๐
Marks node to be freed after the test finishes.
void clear_parameters() ๐
Clears all stored test parameters for the current test context.
Variant create_double(thing: Variant) ๐
Creates a test double (mock or stub) from the provided object, scene, or script.
Variant double_resource(path: String) ๐
Creates a test double (mock/stub) of a specific resource, scene, or script.
Variant double_singleton(name: String) ๐
Creates a test double (mock/stub) of a specific resource, scene, or script.
double_singleton("FakeSingletonName")
void fail_test(text: String = "") ๐
Marks the test as failing. Same as a failing assert.
Returns the total number of asserts this script has made up to this method call.
Call in _after_all() to get total count for a script.
int get_call_count(object: Object, method: StringName, args: Array = []) ๐
Returns the call count for a method with optional args.
Array get_call_parameters(object: Object, method: StringName, index: int = -1) ๐
Get the parameters for a method call to a doubled object.
By default it will return the most recent call.
int get_current_parameter_index() const ๐
Returns the index of the currently active parameter set for a parameterized test.
Returns the total number of failing asserts this script has made up to this method call.
Call in _after_all() to get total count for a script.
Returns the logger instance associated with this test.
int get_parameter_count() const ๐
Returns the total number of parameter sets available for this parameterized test.
Returns the total number of passing asserts this script has made up to this method call.
Call in _after_all() to get total count for a script.
Returns the total number of pending asserts this script has made up to this method call.
Call in _after_all() to get total count for a script.
int get_signal_emit_count(object: Object, signal: StringName) ๐
This will return the number of times a signal was fired.
Array get_signal_parameters(object: Object, signal: StringName, index: int = -1) ๐
Returns the parameters of any watched signal.
This works the same way that assert_signal_emitted_with_parameters() does.
Dictionary get_summary() ๐
Returns a structured summary of the current test execution results.
String get_summary_text() ๐
Returns a human-readable summary of the current test execution results.
Returns the total number of tests in this script.
bool has_parameters() const ๐
Returns true if this test has one or more parameter sets defined.
Alias of print_log()
void pass_test(text: String = "") ๐
Marks the test as passing. Same as a passing assert.
void pending(text: String = "") ๐
Mark the current test as pending.
void print_log(text: String) ๐
Prints a message to the Autowork logger console.
void set_current_parameter_index(index: int) ๐
Sets the current parameter index for a parameterized test execution.
void set_doubler(doubler: AutoworkDoubler) ๐
Sets the AutoworkDoubler instance used by this test.
void set_logger(logger: AutoworkLogger) ๐
Sets the AutoworkLogger instance used by this test.
void set_spy(spy: AutoworkSpy) ๐
Sets the AutoworkSpy instance used by this test.
void set_stubber(stubber: AutoworkStubber) ๐
Sets the AutoworkStubber instance used by this test.
void simulate(node: Node, times: int, delta: float, check_is_processing: bool = false, simulate_method: SimulateMethod = 0) ๐
Simulate a number of frames by calling Node._process() or Node._physics_process() on an object and all of its descendents.
By default it will call both Node._process() and Node._physics_process().
If check_is_processing is true, it will check if node is can process, see Node.is_processing() and Node.is_physics_processing().
bool skip_if_engine_version_lt(version: String, check_godot: bool = false) ๐
Skip test if the Blazium Engine version is less than version ("external_major.external_minor.external_patch").
If check_godot is true, it will check the Godot Engine version instead ("major.minor.patch").
See also Engine.get_version_info().
bool skip_if_engine_version_ne(version: String, check_godot: bool = false) ๐
Skip test if the Blazium Engine version different from version ("external_major.external_minor.external_patch").
If check_godot is true, it will check the Godot Engine version instead ("major.minor.patch").
See also Engine.get_version_info().
bool skip_if_godot_version_lt(version: String) ๐
Alias of skip_if_engine_version_lt().
Skip test if the Godot Engine version is less than version ("major.minor.patch").
This is an alias for skip_if_engine_version_lt().
See also Engine.get_version_info().
bool skip_if_godot_version_ne(version: String) ๐
Alias of skip_if_engine_version_ne().
Skip test if the Godot Engine version different from version ("major.minor.patch").
This is an alias for skip_if_engine_version_ne().
See also Engine.get_version_info().
Variant spy(thing: Variant) ๐
Creates and returns a spy-wrapped version of the provided object.
AutoworkStubParams stub(object: Variant, method: StringName = &"") ๐
Creates a stub configuration for the given object and method.
Variant use_parameters(params: Array) ๐
Sets the parameter sets for a parameterized test.
Signal wait_for_signal(signal: Signal, max_wait: float, message: String = "") ๐
Will wait for signal emission for a max_wait amount of seconds.
This returns timeout, the return value will be true if the signal was emitted, false if max_wait was reached.
var success = await wait_for_signal(player.respawned, 2, "Player should respawn within 2 second")
if success:
pass_test("Player repawned within 2 seconds")
else:
fail_test("Player respawn fail")
Signal wait_physics_frames(frames: int, message: String = "") ๐
Will wait for a number of physics frames, this returns frameout after waiting all frames.
await wait_physics_frames(2, "Wait physics frames completed")
Signal wait_process_frames(frames: int, message: String = "") ๐
Will wait for a number of process frames, this returns frameout after waiting all frames.
await wait_process_frames(2, "Wait process frames completed")
Signal wait_seconds(seconds: float, message: String = "") ๐
Will wait for seconds to pass.
await wait_seconds(2, "Wait 2s completed")
Signal wait_until(callable: Callable, max_wait: float, message: String = "") ๐
Will wait until callable returns true for a max_wait amount of seconds.
This returns timeout, the return value will be true if the callable returned true, false if max_wait was reached.
Signal wait_while(callable: Callable, max_wait: float, message: String = "") ๐
Will wait while callable returns true for a max_wait amount of seconds.
This returns timeout, the return value will be true if the callable returned false, false if max_wait was reached.
void watch_signal(object: Object, signal: StringName) ๐
Starts watching a specific signal emitted by the given object.
void watch_signals(object: Object) ๐
Starts watching all signals emitted by the given object.