Skip to main content

Module test

Module test 

Source
Expand description

Test command — run unit tests against the database.

Executes EXECUTE UNIT TEST statements attached to project objects against a Materialize instance spun up in Docker. The pipeline:

  1. Load — Compile the project and optionally load/generate type metadata.
  2. Filter — Select tests matching the user’s filter pattern (supports database.schema.object#test_name with wildcards at any level).
  3. Connect — Establish a database connection to the target environment.
  4. Execute — For each test: locate the target view, desugar the test into SQL, execute setup statements, run the assertion query, and classify the result.
  5. Report — Print pass/fail output and, when requested, produce a JUnit XML report.

§Outcome Classification

  • Passed — Assertion query returned zero rows (no mismatches).
  • Failed — Assertion query returned rows (missing or unexpected data) or a runtime error occurred during execution.
  • ValidationFailed — Test definition is invalid (bad target, malformed AT TIME, etc.). Tracked separately so summary output distinguishes broken definitions from runtime failures.

Modules§

lower 🔒
Validate a UnitTest and lower it into SQL Materialize can execute.

Structs§

TestFilter 🔒
Filter to select a subset of tests to run.
TestResultEntry 🔒
Per-test result captured during execution and used to build the JUnit report. Serializable so the full result set can be emitted structurally (e.g. for future machine-readable reporting).
TestResults 🔒
Aggregated results of a test run. Acts as the canonical intermediate form from which the JUnit XML report is derived, and is kept serializable so the same shape can back a structured JSON report in the future.
TestSummary 🔒
Aggregate pass/fail counts for the test run.

Enums§

ExecutionFailure 🔒
TestOutcome 🔒
Final classification for a single test invocation.
TestTarget 🔒
Run unit tests against the database.
ValidationFailure 🔒
Pre-execution validation failure in a test definition.

Functions§

extract_assertion_data 🔒
Extracts structured assertion data from failing query rows.
format_assertion_rows 🔒
Formats failing assertion rows into a readable, ANSI-colored table for terminal output.
format_assertion_rows_for_junit 🔒
Formats structured assertion data into plain-text for JUnit XML output.
load_or_generate_types_cache 🔒
Load or generate type metadata needed for test execution.
print_summary 🔒
Prints the test summary line showing pass/fail counts.
print_test_outcome 🔒
Prints the complete status line and any detail output for a single test outcome.
print_test_validation_error 🔒
Renders validation failures in the standard test output format.
run
run_single_test 🔒
Executes one test case through validation, setup SQL, assertion query, and cleanup.
run_tests 🔒
runtime_client 🔒
Creates an isolated runtime client for test execution.
validate_at_time 🔒
Pre-validates optional AT TIME test expressions against mz_timestamp casting.