Testing on Databricks
What to test, per artifact
Coverage matrix for Databricks artifact types — what matters, at which tier, and which tool asserts it.
Use this matrix to decide what a healthy suite covers for each Databricks artifact type. Tiers refer to the test pyramid.
SQL / warehouse queries
- Correctness of logic (joins, window functions, attribution CTEs): local DuckDB tier with committed fixtures. Fast enough to run on every save.
- Engine parity: the same statement on DuckDB and Photon must return
identical rows — run a parity suite with golden results. Catches dialect
divergence (
QUALIFY, timestamp zones, null ordering) before production. - Performance smoke (live, optional): statement completes within a budget on a serverless warehouse.
Delta tables
- Schema contracts: column names, types, nullability against a committed
contract file. Local against DuckDB-created tables; live against
information_schema. - Data quality: row counts, uniqueness, null rates, freshness. Express these
as BDD
Thensteps or SQL predicates. - Constraint / partition layout (live):
DESCRIBE DETAILassertions.
DLT / Lakeflow pipelines
- End-to-end (live,
@dlt): upload fixture files to the ingest location, start a pipeline update, poll to a terminal state, assert the target table contents. - Rescue-data drift: assert
_rescued_datais empty after the run — a non-empty rescue column means the ingestion contract drifted. - Expectations: pipeline expectations (data-quality rules) pass; failed expectation counts are zero.
Jobs and notebooks
- Run-to-terminal (live,
@jobs):run-nowan existing job orruns/submita notebook, wait with a timeout, assertSUCCESSand inspect task output. - Task logic: extract pure logic out of notebooks into packages and unit test it locally — the notebook itself should be a thin shell.
Unity Catalog / governance
- Grant assertions (live): a scoped service principal CAN read allowed
tables and CANNOT read denied ones (expect
PERMISSION_DENIED). Least privilege is a test, not a hope. - Object existence: catalogs, schemas, volumes referenced by config exist.
Lakebase Postgres
- Credential lifecycle (live,
@lakebase): OAuth → credential exchange succeeds, short-lived credentials refresh, connection pool survives the swap. - Migrations: apply idempotently against a scratch branch.
dbt models
dbt buildwith tests against a scratch schema (live) — sources must match the tables the ingestion pipeline actually creates.- Source contract: a boundary test asserting dbt
_sources.ymltable names equal the names emitted by the ingestion code, so the two can never drift.
Statistical / experimentation workloads
- Golden vectors: freeze expected aggregate/stat outputs for committed
fixtures; every engine and every refactor must reproduce them exactly (the
same philosophy as assignment conformance vectors in
packages/testkit). - Guardrails: SRM χ² and metric-decline checks fire on skewed fixtures and stay silent on balanced ones.
Testing on Databricks
A layered testing framework for Databricks artifacts — SQL, Delta tables, DLT pipelines, Jobs, Unity Catalog, Lakebase — with first-class BDD support.
Local testing
Hermetic Databricks tests with no workspace — DuckDB execution contexts, client-boundary mocks, fixtures, and cross-engine parity.