Create basic unit testing framework

This commit is contained in:
2026-03-19 14:24:11 -05:00
parent 57a6643a76
commit b23f6c14b8
6 changed files with 53 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
extends Node
class_name BaseTestRunner
func _ready() -> void:
var methods := self.get_method_list()
for method in methods:
var method_name: String = method["name"]
if method_name.left(5).to_lower() != "test_":
continue
var return_dict: Dictionary = method["return"]
var return_type: int = return_dict["type"]
if return_type != 1:
print_rich("[color=yellow]Skipping Unit Test Method '%s'. Reason: Return type is not bool[/color]" % method_name)
continue
var args: Array = method["args"]
if not args.is_empty():
print_rich("[color=yellow]Skipping Unit Test Method '%s', Reason: Method requires arguments.[/color]" % method_name)
continue
var result: bool = call(method_name)
if result:
print_rich("[color=green]%s: Success![/color]" % method_name)
else:
print_rich("[color=red]%s: Failure...[/color]" % method_name)

View File

@@ -0,0 +1 @@
uid://bsewsmjxlup47

View File

@@ -0,0 +1,3 @@
[gd_scene format=3 uid="uid://rl2o7alqg7w4"]
[node name="BaseTestRunner" type="Node" unique_id=1916529975]

View File

@@ -0,0 +1,14 @@
extends BaseTestRunner
func Test_1() -> bool:
var json_string = "{\"Key\": false}"
var json = JSON.new()
var parse_result := json.parse(json_string)
if parse_result != OK:
return false
return true
func Test_2() -> String:
return ''

View File

@@ -0,0 +1 @@
uid://xrexdmk7d1qx

View File

@@ -0,0 +1,6 @@
[gd_scene format=3 uid="uid://c23ct3b1nmih7"]
[ext_resource type="Script" uid="uid://xrexdmk7d1qx" path="res://Debug/Unit Testing/Scripts/json_parsing_tests.gd" id="1_beu12"]
[node name="JsonParsingTests" type="Node" unique_id=2014332517]
script = ExtResource("1_beu12")