Skip to content

Commit

Permalink
GD-635: Fix GdUnit console test counters (#665)
Browse files Browse the repository at this point in the history
# What
- removed obsolete TESTCASE_STATISTICS event
- fix test counter on the console
- fix counting based on TESTCASE_AFTER because we removed
TESTCASE_STATISTICS
- fix initial progress counter
- fix skipped test reporting for parameterized tests
  • Loading branch information
MikeSchulze authored Feb 5, 2025
1 parent ac87465 commit 2e6f41d
Show file tree
Hide file tree
Showing 11 changed files with 70 additions and 149 deletions.
3 changes: 0 additions & 3 deletions addons/gdUnit4/bin/GdUnitCmdTool.gd
Original file line number Diff line number Diff line change
Expand Up @@ -504,9 +504,6 @@ class CLIRunner:
event.is_flaky(),
event.elapsed_time())
_report.add_testcase_reports(event.resource_path(), event.test_name(), event.reports())
GdUnitEvent.TESTCASE_STATISTICS:
_report.update_testsuite_counters(event.resource_path(), event.is_error(), event.failed_count(), event.orphan_nodes(),\
event.is_skipped(), event.is_flaky(), event.elapsed_time())
print_status(event)


Expand Down
10 changes: 0 additions & 10 deletions addons/gdUnit4/src/core/event/GdUnitEvent.gd
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ enum {
TESTSUITE_AFTER,
TESTCASE_BEFORE,
TESTCASE_AFTER,
TESTCASE_STATISTICS,
DISCOVER_START,
DISCOVER_END,
DISCOVER_SUITE_ADDED,
Expand Down Expand Up @@ -74,15 +73,6 @@ func test_after(p_resource_path :String, p_suite_name :String, p_test_name :Stri
return self


func test_statistics(p_resource_path :String, p_suite_name :String, p_test_name :String, p_statistics :Dictionary = {}) -> GdUnitEvent:
_event_type = TESTCASE_STATISTICS
_resource_path = p_resource_path
_suite_name = p_suite_name
_test_name = p_test_name
_statistics = p_statistics
return self


func type() -> int:
return _event_type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ func _execute(context :GdUnitExecutionContext) -> void:
await context.gc()
await context.error_monitor_stop()

# finally fire test statistics report
fire_event(GdUnitEvent.new()\
.test_statistics(context.get_test_suite_path(),
context.get_test_suite_name(),
context.get_test_case_name(),
context.get_execution_statistics()))

# finally free the test instance
if is_instance_valid(context.test_case):
context.test_case.dispose()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,12 @@ func fire_test_suite_skipped(context :GdUnitExecutionContext) -> void:
var test_case_context := GdUnitExecutionContext.of_test_case(context, test_case)
fire_event(GdUnitEvent.new()\
.test_before(test_case_context.get_test_suite_path(), test_case_context.get_test_suite_name(), test_case_context.get_test_case_name()))
fire_test_skipped(test_case_context)

if test_case.is_parameterized():
for test_name in test_case.test_case_names():
fire_test_skipped(GdUnitExecutionContext.of_parameterized_test(test_case_context, test_name, []))
else:
fire_test_skipped(test_case_context)


var statistics := {
Expand Down Expand Up @@ -139,12 +144,6 @@ func fire_test_skipped(context: GdUnitExecutionContext) -> void:
context.get_test_case_name(),
statistics,
[report]))
# finally fire test statistics report
fire_event(GdUnitEvent.new()\
.test_statistics(context.get_test_suite_path(),
context.get_test_suite_name(),
context.get_test_case_name(),
statistics))


func set_debug_mode(debug_mode :bool = false) -> void:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ func fixure_typed_parameters(parameter_sets: Array, arg_descriptors: Array[GdFun
return parameter_sets



static func copy_properties(source: Object, dest: Object) -> void:
for property in source.get_property_list():
var property_name :String = property["name"]
Expand Down
94 changes: 52 additions & 42 deletions addons/gdUnit4/src/ui/GdUnitConsole.gd
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,7 @@ var _text_color: Color
var _function_color: Color
var _engine_type_color: Color
var _statistics := {}
var _summary := {
"total_count": 0,
"error_count": 0,
"failed_count": 0,
"skipped_count": 0,
"flaky_count": 0,
"orphan_nodes": 0
}
var _summary := {}


@warning_ignore("return_value_discarded")
Expand Down Expand Up @@ -56,34 +49,52 @@ func init_colors() -> void:
_engine_type_color = settings.get_setting("text_editor/theme/highlighting/engine_type_color")


func init_statistics(event: GdUnitEvent) -> void:
_statistics["total_count"] = event.total_count()
_statistics["error_count"] = 0
_statistics["failed_count"] = 0
_statistics["skipped_count"] = 0
_statistics["flaky_count"] = 0
_statistics["orphan_nodes"] = 0
_summary["total_count"] += event.total_count()
func init_summary() -> void:
_summary["total_count"] = 0
_summary["error_count"] = 0
_summary["failed_count"] = 0
_summary["skipped_count"] = 0
_summary["flaky_count"] = 0
_summary["orphan_nodes"] = 0


func reset_statistics() -> void:
for k: String in _statistics.keys():
_statistics[k] = 0
for k: String in _summary.keys():
_summary[k] = 0
func init_statistics() -> void:
_statistics.clear()


func update_statistics(event: GdUnitEvent) -> void:
_statistics["error_count"] += event.error_count()
_statistics["failed_count"] += event.failed_count()
_statistics["skipped_count"] += event.is_skipped() as int
_statistics["flaky_count"] += event.is_flaky() as int
_statistics["orphan_nodes"] += event.orphan_nodes()
_summary["error_count"] += event.error_count()
_summary["failed_count"] += event.failed_count()
_summary["skipped_count"] += event.is_skipped() as int
_summary["flaky_count"] += event.is_flaky() as int
_summary["orphan_nodes"] += event.orphan_nodes()
var test_statisitics: Dictionary = _statistics.get_or_add(event.test_name(), {
"error_count" : 0,
"failed_count" : 0,
"skipped_count" : event.is_skipped() as int,
"flaky_count" : 0,
"orphan_nodes" : 0
})
test_statisitics["error_count"] = event.is_error() as int
test_statisitics["failed_count"] = event.is_failed() as int
test_statisitics["flaky_count"] = event.is_flaky() as int
test_statisitics["orphan_nodes"] = event.orphan_nodes()


func get_value(acc: int, value: Dictionary, key: String) -> int:
return acc + value[key]


func update_summary() -> Dictionary:
var statistic := {
"total_count" : _statistics.size(),
"error_count" : 0,
"failed_count" : 0,
"skipped_count" : 0,
"flaky_count" : 0,
"orphan_nodes" : 0
}
_summary["total_count"] += _statistics.size()
for key: String in ["error_count", "failed_count", "skipped_count", "flaky_count", "orphan_nodes"]:
var value: int = _statistics.values().reduce(get_value.bind(key), 0 )
statistic[key] = value
_summary[key] += value
return statistic


func print_message(message: String, color: Color=_text_color, indent:=0) -> void:
Expand Down Expand Up @@ -140,7 +151,7 @@ func setup_update_notification(control: Button) -> void:
func _on_gdunit_event(event: GdUnitEvent) -> void:
match event.type():
GdUnitEvent.INIT:
reset_statistics()
init_summary()

GdUnitEvent.STOP:
print_message("Summary:", Color.DODGER_BLUE)
Expand All @@ -155,11 +166,12 @@ func _on_gdunit_event(event: GdUnitEvent) -> void:
print_message("[wave][/wave]")

GdUnitEvent.TESTSUITE_BEFORE:
init_statistics(event)
init_statistics()
print_message("Execute: ", Color.DODGER_BLUE)
println_message(event._suite_name, _engine_type_color)

GdUnitEvent.TESTSUITE_AFTER:
var statistics := update_summary()
if not event.reports().is_empty():
println_message("\t" + event._suite_name, _engine_type_color)
for report: GdUnitReport in event.reports():
Expand All @@ -171,12 +183,12 @@ func _on_gdunit_event(event: GdUnitEvent) -> void:
else:
print_message("[shake rate=5 level=10][b]FAILED[/b][/shake]", Color.FIREBRICK)
print_message(" | %d total | %d error | %d failed | %d flaky | %d skipped | %d orphans |" %\
[_statistics["total_count"],
_statistics["error_count"],
_statistics["failed_count"],
_statistics["flaky_count"],
_statistics["skipped_count"],
_statistics["orphan_nodes"]])
[statistics["total_count"],
statistics["error_count"],
statistics["failed_count"],
statistics["flaky_count"],
statistics["skipped_count"],
statistics["orphan_nodes"]])
println_message("%+12s" % LocalTime.elapsed(event.elapsed_time()))
println_message(" ")

Expand All @@ -188,6 +200,7 @@ func _on_gdunit_event(event: GdUnitEvent) -> void:
print_message(("%" + spaces + "s") % event._test_name, _function_color)

GdUnitEvent.TESTCASE_AFTER:
update_statistics(event)
var reports := event.reports()
if event.is_flaky() and event.is_success():
var retries :int = event.statistic(GdUnitEvent.RETRY_COUNT)
Expand All @@ -209,9 +222,6 @@ func _on_gdunit_event(event: GdUnitEvent) -> void:
for report: GdUnitReport in event.reports():
println_message("line %s: %s" % [line_number(report), report._message], _text_color, 2)

GdUnitEvent.TESTCASE_STATISTICS:
update_statistics(event)


func _on_gdunit_client_connected(client_id: int) -> void:
output.clear()
Expand Down
20 changes: 6 additions & 14 deletions addons/gdUnit4/src/ui/parts/InspectorStatusBar.gd
Original file line number Diff line number Diff line change
Expand Up @@ -133,20 +133,12 @@ func _on_gdunit_event(event: GdUnitEvent) -> void:
total_errors = 0
total_flaky = 0
status_changed(0, 0, 0)
GdUnitEvent.TESTCASE_BEFORE:
pass
GdUnitEvent.TESTCASE_STATISTICS:
if event.is_error():
status_changed(event.error_count(), 0, event.is_flaky())
else:
status_changed(0, event.failed_count(), event.is_flaky())
GdUnitEvent.TESTSUITE_BEFORE:
pass
GdUnitEvent.TESTSUITE_AFTER:
if event.is_error():
status_changed(event.error_count(), 0, 0)
else:
status_changed(0, event.failed_count(), 0)

GdUnitEvent.TESTCASE_AFTER:
status_changed(event.error_count(), event.failed_count(), event.is_flaky())

#GdUnitEvent.TESTSUITE_AFTER:
# status_changed(event.error_count(), event.failed_count(), event.is_flaky())


func _on_btn_error_up_pressed() -> void:
Expand Down
1 change: 1 addition & 0 deletions addons/gdUnit4/src/ui/parts/InspectorTreeMainPanel.gd
Original file line number Diff line number Diff line change
Expand Up @@ -312,6 +312,7 @@ func reset_tree_state(parent: TreeItem) -> void:
if parent == _tree_root:
_tree_root.set_meta(META_GDUNIT_TEST_INDEX, 0)
_tree_root.set_meta(META_GDUNIT_STATE, STATE.INITIAL)
test_counters_changed.emit(0, 0, STATE.INITIAL)

for item in parent.get_children():
set_state_initial(item)
Expand Down
2 changes: 1 addition & 1 deletion addons/gdUnit4/test/GdUnitTestSuiteTest.gd
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func collect_report(event :GdUnitEvent) -> void:
func before() -> void:
# register to receive test reports
GdUnitSignals.instance().gdunit_event.connect(collect_report)
_flaky_settings = ProjectSettings.get_setting(GdUnitSettings.TEST_FLAKY_CHECK)
_flaky_settings = ProjectSettings.get_setting(GdUnitSettings.TEST_FLAKY_CHECK, false)
ProjectSettings.set_setting(GdUnitSettings.TEST_FLAKY_CHECK, true)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ func do_a_fail() -> void:


func catch_test_events(event :GdUnitEvent) -> void:
# we not catch the statistics
if event.type() != GdUnitEvent.TESTCASE_STATISTICS:
_catched_events.append(event)
_catched_events.append(event)


func before() -> void:
Expand Down
Loading

0 comments on commit 2e6f41d

Please sign in to comment.