module Lapis::Docs::H_TESTING_AND_BENCHMARKS::A_TESTING_FRAMEWORK

Overview

Unified Testing Framework & Leak Verification

Comprehensive guide to the Lapis::Test apparatus, authoring automated test suites, running headless in-editor tool tests, and quantitatively proving zero memory leaks.

Executive Summary & Key Topics

Topic Method / Anchor Description
Testing Apparatus Features .topic_00_test_capabilities Declarative test_suite DSL, lifecycle fixtures, and engine performance monitors.
Authoring a Test Suite .topic_01_writing_suites Creating test suites in spec/suites/ with custom assertions.
Proving Zero Leaks with assert_no_leak .topic_02_zero_leak_verification Using Godot's Performance monitors and Boehm GC to mathematically prove zero memory leaks.

Related Guides & Source References

Defined in:

libgodot/docs/h_testing_and_benchmarks/a_testing_framework.cr

Class Method Summary

Class Method Detail

def self.topic_00_test_capabilities : Nil #

Testing Apparatus Features: Declarative test_suite DSL, lifecycle fixtures, and engine performance monitors.

Key Topics & Information

  • Declarative syntax: test_suite "Name" do ... test "Case" do ... end end
  • Lifecycle fixtures: before_each and after_each setup hooks
  • Quantitative zero memory leak verification via assert_no_leak
  • Dual execution: Run headlessly in CI or interactively in Godot Editor Test Runner Dock

def self.topic_01_writing_suites : Nil #

Authoring a Test Suite: Creating test suites in spec/suites/ with custom assertions.

require "../spec_helper"

test_suite "Combat Mechanics" do
  before_each do
    @player = Godot.create(Godot::CharacterBody2D)
  end

  after_each do
    @player.destroy if @player.alive?
  end

  test "player takes damage correctly" do
    combat = CombatSystem.new(@player)
    combat.apply_damage(20)
    combat.health.should eq(80)
  end
end

def self.topic_02_zero_leak_verification : Nil #

Proving Zero Leaks with assert_no_leak: Using Godot's Performance monitors and Boehm GC to mathematically prove zero memory leaks.

Memory leaks are fatal in game development. Lapis provides assert_no_leak:

test "1,000 bullet spawns do not leak engine memory" do
  Lapis::Test.assert_no_leak(warmup: 5, iterations: 100) do
    bullet = Godot.create(Godot::Sprite2D)
    get_tree.root.add_child(bullet)
    bullet.queue_free
  end
end

How It Works:

  1. Runs warmup iterations to stabilize caches.
  2. Records initial OBJECT_COUNT, OBJECT_NODE_COUNT, and MEMORY_STATIC.
  3. Executes the test block across batch iterations.
  4. Forces GC.collect and pumps Godot frames to flush deferred deletions.
  5. Mathematically asserts that final object count exactly equals initial object count!