Asserts - MikeSchulze/gdUnit3 Wiki

Original URL: https://github.com/MikeSchulze/gdUnit3/wiki/Asserts

🚨 github-wiki-see.page does not render Org-Mode. Source for crawling below. Please visit the Original URL! 🚨


*  A Overview of the GdUnit Asserts
GdUnit is providing a set of assertions where give you helpful error messages and improves yor test code readability.
Assertions are type organized and supports fluent syntax writing.

Examples of assertions:
``` python
# using common assert
assert_that(person.name()).is_equal("Hoschi")
assert_that(person.age()).is_equal(42)

# using type save assert
assert_str(person.address()).starts_with("Route 66") \
    .ends_with("USA.") \
    .not_contains("Santa")

# using type save assert
assert_arr(person.childrens()).has_size(4) \
   .contains(["Max", "Moriz"]) \
   .not_contains(["Luzi"])

*** Basic Build-In Type Asserts |Assert|Type| |[[assert_bool|Asserts#assert_bool]] | bool | |[[assert_int|Asserts#assert_int]] | int| |[[assert_float|Asserts#assert_float]] | float| |[[assert_str|Asserts#assert_str]] | String|

For more details about Build-In types click here [[https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html#basic-built-in-types][Godot Build-In Types]]

** Container Built-In Type Asserts |Assert|Type| |[[assert_array|Asserts#assert_array]] | Array, PoolByteArray, PoolIntArray, PoolRealArray, PoolStringArray, PoolVector2Array, PoolVector3Array, PoolColorArray| |[[assert_dict|Asserts#assert_dict]] | Dictionary|

For more details about Build-In types click here [[https://docs.godotengine.org/en/stable/getting_started/scripting/gdscript/gdscript_basics.html#container-built-in-types][Container built-in types]]

*** Engine Build-In Type Asserts |Type|Assert| |[[assert_vector2|Asserts#assert_vector2]] | Vector2| |[[assert_vector3|Asserts#assert_vector3]] | Vector3| |[[assert_object|Asserts#assert_object]] | Object| |[[assert_file|Asserts#assert_file]] | File|

*** The Common Assert Can be used for all types, gives you access to the basic test functions of GdUnitAssert.

You should only use this assert type if you don't know the type you want to test.

I recommend to always use the type-safe assert type such as assert_str to test for a string.

|Assert|Type| |[[assert_that|Asserts#assert_that]]| auto typing|

** assert_bool /GdUnitBoolAssert/

An assertion tool to verify boolean values.

|Function|Description| |[[is_null|GdUnitBoolAssert#is_null]]| Verifies that the current value is null.| |[[is_not_null|GdUnitBoolAssert#is_not_null]]| Verifies that the current value is not null.| |[[is_equal|GdUnitBoolAssert#is_equal]]| Verifies that the current value is equal to the given one.| |[[is_not_equal|GdUnitBoolAssert#is_not_equal]]| Verifies that the current value is not equal to the given one.| |[[is_true|GdUnitBoolAssert#is_true]] | Verifies that the current value is true.| |[[is_false|GdUnitBoolAssert#is_false]]| Verifies that the current value is false.|

** assert_int /GdUnitIntAssert/

An assertion tool to verify integer values.

|Function|Description| |[[is_null|GdUnitIntAssert#is_null]]| Verifies that the current value is null.| |[[is_not_null|GdUnitIntAssert#is_not_null]]| Verifies that the current value is not null.| |[[is_equal|GdUnitIntAssert#is_equal]]| Verifies that the current value is equal to the given one.| |[[is_not_equal|GdUnitIntAssert#is_not_equal]]| Verifies that the current value is not equal to the given one.| |[[is_less|GdUnitIntAssert#is_less]]| Verifies that the current value is less than the given one.| |[[is_less_equal|GdUnitIntAssert#is_less_equal]]| Verifies that the current value is less than or equal the given one.| |[[is_greater|GdUnitIntAssert#is_greater]]| Verifies that the current value is greater than the given one.| |[[is_greater_equal|GdUnitIntAssert#is_greater_equal]]| Verifies that the current value is greater than or equal the given one.| |[[is_even|GdUnitIntAssert#is_even]] | Verifies that the current value is even.| |[[is_odd|GdUnitIntAssert#is_odd]] | Verifies that the current value is odd.| |[[is_negative|GdUnitIntAssert#is_negative]] | Verifies that the current value is negative.| |[[is_not_negative|GdUnitIntAssert#is_not_negative]] | Verifies that the current value is not negative.| |[[is_zero|GdUnitIntAssert#is_zero]] | Verifies that the current value is equal to zero.| |[[is_not_zero|GdUnitIntAssert#is_not_zero]] | Verifies that the current value is not equal to zero.| |[[is_in|GdUnitIntAssert#is_in]]| Verifies that the current value is in the given set of values.| |[[is_not_in|GdUnitIntAssert#is_not_in]]| Verifies that the current value is not in the given set of values.| |[[is_between|GdUnitIntAssert#is_between]] | Verifies that the current value is between the given boundaries (inclusive).|

** assert_float /GdUnitFloatAssert/

An assertion tool to verify float values.

|Function|Description| |[[is_null|GdUnitFloatAssert#is_null]]| Verifies that the current value is null.| |[[is_not_null|GdUnitFloatAssert#is_not_null]]| Verifies that the current value is not null.| |[[is_equal|GdUnitFloatAssert#is_equal]] | Verifies that the current value is equal to the given one.| |[[is_not_equal|GdUnitFloatAssert#is_not_equal]] | Verifies that the current value is not equal to the given one.| |[[is_equal_approx|GdUnitFloatAssert#is_equal_approx]] | Verifies that the current and expected value are approximately equal.| |[[is_less|GdUnitFloatAssert#is_less]] | Verifies that the current value is less than the given one.| |[[is_less_equal|GdUnitFloatAssert#is_less_equal]] | Verifies that the current value is less than or equal the given one.| |[[is_greater|GdUnitFloatAssert#is_greater]] | Verifies that the current value is greater than the given one.| |[[is_greater_equal|GdUnitFloatAssert#is_greater_equal]] | Verifies that the current value is greater than or equal the given one.| |[[is_negative|GdUnitFloatAssert#is_negative]] | Verifies that the current value is negative.| |[[is_not_negative|GdUnitFloatAssert#is_not_negative]] | Verifies that the current value is not negative.| |[[is_zero|GdUnitFloatAssert#is_zero]] | Verifies that the current value is equal to zero.| |[[is_not_zero|GdUnitFloatAssert#is_not_zero]] | Verifies that the current value is not equal to zero.| |[[is_in|GdUnitFloatAssert#is_in]] | Verifies that the current value is in the given set of values.| |[[is_not_in|GdUnitFloatAssert#is_not_in]] | Verifies that the current value is not in the given set of values.| |[[is_between|GdUnitFloatAssert#is_between]] | Verifies that the current value is between the given boundaries (inclusive).|

** assert_str /GdUnitStringAssert/

An assertion tool to verify String values.

|Function|Description| |[[is_null|GdUnitStringAssert#is_null]]| Verifies that the current value is null.| |[[is_not_null|GdUnitStringAssert#is_not_null]]| Verifies that the current value is not null.| |[[is_equal|GdUnitStringAssert#is_equal]] | Verifies that the current String is equal to the given one.| |[[is_equal_ignoring_case|GdUnitStringAssert#is_equal_ignoring_case]] | Verifies that the current String is equal to the given one, ignoring case considerations.| |[[is_not_equal|GdUnitStringAssert#is_not_equal]] | Verifies that the current String is not equal to the given one.| |[[is_not_equal_ignoring_case|GdUnitStringAssert#is_not_equal_ignoring_case]] | Verifies that the current String is not equal to the given one, ignoring case considerations.| |[[is_empty|GdUnitStringAssert#is_empty]] | Verifies that the current String is empty, it has a length of 0.| |[[is_not_empty|GdUnitStringAssert#is_not_empty]] | Verifies that the current String is not empty, it has a length of minimum 1.| |[[contains|GdUnitStringAssert#contains]] | Verifies that the current String contains the given String.| |[[contains_ignoring_case|GdUnitStringAssert#contains_ignoring_case]] | Verifies that the current String does not contain the given String, ignoring case considerations.| |[[not_contains|GdUnitStringAssert#not_contains]] | Verifies that the current String does not contain the given String.| |[[not_contains_ignoring_case|GdUnitStringAssert#not_contains_ignoring_case]]| Verifies that the current String does not contain the given String, ignoring case considerations.| |[[starts_with|GdUnitStringAssert#starts_with]] | Verifies that the current String starts with the given prefix.| |[[ends_with|GdUnitStringAssert#ends_with]] | Verifies that the current String ends with the given suffix.| |[[has_length|GdUnitStringAssert#has_length]] | Verifies that the current String has the expected length by used comparator.|

** assert_vector2 /GdUnitVector2Assert/

An assertion tool to verify Vector2 values.

|Function|Description| |[[is_null|GdUnitVector2Assert#is_null]]| Verifies that the current value is null.| |[[is_not_null|GdUnitVector2Assert#is_not_null]]| Verifies that the current value is not null.| |[[is_equal|GdUnitVector2Assert#is_equal]] | Verifies that the current value is equal to the given one.| |[[is_not_equal|GdUnitVector2Assert#is_not_equal]] | Verifies that the current value is not equal to the given one.| |[[is_equal_approx|GdUnitVector2Assert#is_equal_approx]] | Verifies that the current and expected value are approximately equal.| |[[is_less|GdUnitVector2Assert#is_less]] | Verifies that the current value is less than the given one.| |[[is_less_equal|GdUnitVector2Assert#is_less_equal]] | Verifies that the current value is less than or equal the given one.| |[[is_greater|GdUnitVector2Assert#is_greater]] | Verifies that the current value is greater than the given one.| |[[is_greater_equal|GdUnitVector2Assert#is_greater_equal]] | Verifies that the current value is greater than or equal the given one.| |[[is_between|GdUnitVector2Assert#is_between]] | Verifies that the current value is between the given boundaries (inclusive).| |[[is_not_between|GdUnitVector2Assert#is_not_between]] | Verifies that the current value is not between the given boundaries (inclusive).|

** assert_vector3 /GdUnitVector3Assert/

An assertion tool to verify Vector3 values.

|Function|Description| |[[is_null|GdUnitVector3Assert#is_null]]| Verifies that the current value is null.| |[[is_not_null|GdUnitVector3Assert#is_not_null]]| Verifies that the current value is not null.| |[[is_equal|GdUnitVector3Assert#is_equal]] | Verifies that the current value is equal to the given one.| |[[is_not_equal|GdUnitVector3Assert#is_not_equal]] | Verifies that the current value is not equal to the given one.| |[[is_equal_approx|GdUnitVector3Assert#is_equal_approx]] | Verifies that the current and expected value are approximately equal.| |[[is_less|GdUnitVector3Assert#is_less]] | Verifies that the current value is less than the given one.| |[[is_less_equal|GdUnitVector3Assert#is_less_equal]] | Verifies that the current value is less than or equal the given one.| |[[is_greater|GdUnitVector3Assert#is_greater]] | Verifies that the current value is greater than the given one.| |[[is_greater_equal|GdUnitVector3Assert#is_greater_equal]] | Verifies that the current value is greater than or equal the given one.| |[[is_between|GdUnitVector3Assert#is_between]] | Verifies that the current value is between the given boundaries (inclusive).| |[[is_not_between|GdUnitVector3Assert#is_not_between]] | Verifies that the current value is not between the given boundaries (inclusive).|

** assert_array /GdUnitArrayAssert/

An assertion tool to verify arrays.

|Function|Description|Since| |[[is_null|GdUnitArrayAssert#is_null]] | Verifies that the current value is null.| | |[[is_not_null|GdUnitArrayAssert#is_not_null]] | Verifies that the current value is not null.| | |[[is_equal|GdUnitArrayAssert#is_equal]] | Verifies that the current Array is equal to the given one.| | |[[is_equal_ignoring_case|GdUnitArrayAssert#is_equal_ignoring_case]] | Verifies that the current Array is equal to the given one, ignoring case considerations.| | |[[is_not_equal|GdUnitArrayAssert#is_not_equal]] | Verifies that the current Array is not equal to the given one.| | |[[is_not_equal_ignoring_case|GdUnitArrayAssert#is_not_equal_ignoring_case]] | Verifies that the current Array is not equal to the given one, ignoring case considerations.| | |[[is_empty|GdUnitArrayAssert#is_empty]] | Verifies that the current Array is empty, it has a size of 0.| | |[[is_not_empty|GdUnitArrayAssert#is_not_empty]] | Verifies that the current Array is not empty, it has a size of minimum 1.| | |[[has_size|GdUnitArrayAssert#has_size]] | Verifies that the current Array has a size of given value.| | |[[contains|GdUnitArrayAssert#contains]] | Verifies that the current Array contains the given values, in any order.| | |[[contains_exactly|GdUnitArrayAssert#contains_exactly]] | Verifies that the current Array contains exactly only the given values and nothing else, in same order.| | |[[contains_exactly_in_any_order|GdUnitArrayAssert#contains_exactly_in_any_order]] | Verifies that the current Array contains exactly only the given values and nothing else, in any order.| 1.0.2| |[[extract|GdUnitArrayAssert#extract]] | Extracts all values by given function name and optional arguments.| | |[[extractv|GdUnitArrayAssert#extractv]] | Extracts all values by given extractor's.| |

** assert_dict /GdUnitDictionaryAssert/

An assertion tool to verify dictionaries.

|Function|Description| |[[is_null|GdUnitDictionaryAssert#is_null]] | Verifies that the current value is null.| |[[is_not_null|GdUnitDictionaryAssert#is_not_null]] | Verifies that the current value is not null.| |[[is_equal|GdUnitDictionaryAssert#is_equal]] | Verifies that the current dictionary is equal to the given one, ignoring order.| |[[is_not_equal|GdUnitDictionaryAssert#is_not_equal]] | Verifies that the current dictionary is not equal to the given one, ignoring order.| |[[is_empty|GdUnitDictionaryAssert#is_empty]] | Verifies that the current dictionary is empty, it has a size of 0.| |[[is_not_empty|GdUnitDictionaryAssert#is_not_empty]] | Verifies that the current dictionary is not empty, it has a size of minimum 1.| |[[has_size|GdUnitDictionaryAssert#has_size]] | Verifies that the current dictionary has a size of given value.| |[[contains_keys|GdUnitDictionaryAssert#contains_keys]]| Verifies that the current dictionary contains the given keys.| |[[contains_not_keys|GdUnitDictionaryAssert#contains_not_keys]]| Verifies that the current dictionary not contains the given keys.| |[[contains_key_value|GdUnitDictionaryAssert#contains_key_value]]| Verifies that the current dictionary contains the given key and value.|

** assert_object /GdUnitObjectAssert/

An assertion tool to verify Objects.

|Function|Description| |[[is_null|GdUnitObjectAssert#is_null]]| Verifies that the current value is null.| |[[is_not_null|GdUnitObjectAssert#is_not_null]]| Verifies that the current value is not null.| |[[is_equal|GdUnitObjectAssert#is_equal]]| Verifies that the current value is equal to expected one.| |[[is_not_equal|GdUnitObjectAssert#is_not_equal]]| Verifies that the current value is not equal to expected one.| |[[is_same|GdUnitObjectAssert#is_same]]| Verifies that the current value is the same as the given one.| |[[is_not_same|GdUnitObjectAssert#is_not_same]]| Verifies that the current value is not the same as the given one.| |[[is_instanceof|GdUnitObjectAssert#is_instanceof]]| Verifies that the current value is an instance of the given type.| |[[is_not_instanceof|GdUnitObjectAssert#is_not_instanceof]]| Verifies that the current value is not an instance of the given type.|

** assert_func /GdUnitFuncAssert/ since v1.0.6

An assertion tool that waits until a certain time for an expected function return value. When the timeout is reached, the assertion fails with a timeout error. The default timeout of 2s can be overridden by wait_until()

|Function|Description| |[[is_null|GdUnitFuncAssert#is_null]]| Verifies that the current value is null.| |[[is_not_null|GdUnitFuncAssert#is_not_null]]| Verifies that the current value is not null.| |[[is_equal|GdUnitFuncAssert#is_equal]]| Verifies that the current value is equal to expected one.| |[[is_not_equal|GdUnitFuncAssert#is_not_equal]]| Verifies that the current value is not equal to expected one.| |[[is_true|GdUnitFuncAssert#is_true]] | Verifies that the current value is true.| |[[is_false|GdUnitFuncAssert#is_false]]| Verifies that the current value is false.| |[[wait_until|GdUnitFuncAssert#wait_until]]| Sets the timeout in ms to wait the function returnd the expected value.|

** assert_signal /GdUnitSignalAssert/ since v1.0.6

An Assertion Tool to verify for emitted signals until a certain time. When the timeout is reached, the assertion fails with a timeout error. The default timeout of 2s can be overridden by wait_until()

|Function|Description| |[[is_emitted|GdUnitSignalAssert#is_emitted]]| Verifies that given signal is emitted until waiting time.| |[[is_not_emitted|GdUnitSignalAssert#is_not_emitted]]| Verifies that given signal is NOT emitted until waiting time.| |[[wait_until|GdUnitSignalAssert#wait_until]]| Sets the assert signal timeout in ms.|

** assert_result /GdUnitResultAssert/

An assertion tool to verify a Result.

|Function|Description| |[[is_null|GdUnitResultAssert#is_null]]| Verifies that the current value is null.| |[[is_not_null|GdUnitResultAssert#is_not_null]]| Verifies that the current value is not null.| |[[is_success|GdUnitResultAssert#is_success]]| Verifies that the result is ends up with success.| |[[is_warning|GdUnitResultAssert#is_warning]]| Verifies that the result is ends up with warning.| |[[is_error|GdUnitResultAssert#is_error]]| Verifies that the result is ends up with error.| |[[contains_message|GdUnitResultAssert#contains_message]]| Verifies that the result contains the given message.| |[[is_value|GdUnitResultAssert#is_value]]| Verifies that the result contains the given value.|

** assert_file /GdUnitFileAssert/ |Function|Description| |is_file() | | |exists() | | |is_script() | | |contains_exactly | |

** assert_that The assert_that is usefull if you not now about the type you want to test. You can use this assert on all types you want but for better test readability i prefear to use type save asserts.

/GdUnitAssert/ |Function|Description| |test_fail()|Let the test fail| |[[is_null|Asserts#is_null]]| Verifies that the current value is null.| |[[is_not_null|Asserts#is_not_null]]| Verifies that the current value is not null.| |[[is_equal|Asserts#is_equal]] | Verifies that the current value is equal to the given one.| |[[is_not_equal|Asserts#is_not_equal]] | Verifies that the current value is not equal to the given one.| |[[has_failure_message|Asserts#has_failure_message]] | Verifies the failure message is equal to expected one.| |[[starts_with_failure_message|Asserts#starts_with_failure_message]] | Verifies that the failure starts with the given prefix.| |[[override_failure_message|Asserts#override_failure_message]]| Overrides the default failure message by given custom message. |