/bigtesty:writing-testsfrom BigTesty
Writes BigTesty test files (*.bigtesty.yaml) for BigQuery SQL. Covers given rows, when step, then assertions (expected rows, row_count, Python functions), and generating tests with --update.
Ships in BigTesty. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
A test file *.bigtesty.yaml (or .yml / .json) in the tests directory of the config holds scenarios. Each
scenario gets its own datasets, so the scenarios run in parallel and never see each other's data.
Order of a scenario: the ddl_files of the config, given (load the rows), when (the SQL under test), then
(the assertions).
# yaml-language-server: $schema=https://raw.githubusercontent.com/tosun-si/bigtesty/main/schemas/bigtesty-test.schema.json
description: Upsert of the failures summary with a MERGE
scenarios:
- name: merge_updates_existing_and_inserts_new_features # unique in the file, snake_case
given:
- table: monitoring.job_failure
rows:
- { featureName: featurePSG, jobName: job1, dwhCreationDate: "2026-01-10 10:00:00" }
- table: monitoring.job_failure_summary
rows_file: given/existing_summary.json
when:
sql_file: when/merge_failures_summary.sql # or sql: inline
then:
- name: summary_is_upserted
table: monitoring.job_failure_summary # SELECT * of the table
expected_file: then/expected_summary.json
- name: no_duplicated_feature
query: SELECT featureName FROM monitoring.job_failure_summary GROUP BY featureName HAVING COUNT(*) > 1
row_count: 0
when.sql_file / query_file instead of copying it, e.g.
../../src/monitoring/sql/job.sql (paths are relative to the test file): the references to the configured
datasets (monitoring.t, `my-prod-project.monitoring.t` with project_aliases) are rewritten to the
scenario datasets. Every dataset of the SQL must be declared in bigtesty.yaml. Never copy the SQL into the tests
or generate a copy: the copy drifts from the production.when is optional and runs as a BigQuery script: DML, MERGE, CALL, DECLARE, BEGIN...END. To test a plain
query, skip when and put the query in the then.given rows only need the columns that matter; they are loaded with the table schema (a wrong type fails the
scenario). Load jobs are free, only the query jobs are billed (at least 10 MiB each).@name): parameters on the scenario (when and all the then), on the when, on a then
(overrides). Type inferred (string, integer, float, boolean, arrays of them), or explicit:
since: { type: DATE, value: "2026-01-01" } (also TIMESTAMP, DATETIME, NUMERIC, JSON..., and nulls).{{ ds }}, Jinja, Airflow macros, an in-house engine): BigTesty doesn't render them itself. Declare
the engine of the team in bigtesty.yaml and pass vars per scenario:# bigtesty.yaml
sql_renderer: { module: tests/render.py, function: render } # render(sql, vars[, path=]) -> str
vars: { env: test } # defaults, overridden by the scenario vars
# tests/render.py: call the production rendering code, so that the tests render the SQL like the production
from monitoring.templating import render_sql # e.g. the Jinja environment of the production
def render(sql: str, vars: dict) -> str:
return render_sql(sql, **vars)
Never reimplement the template engine for the tests: find the function the production uses to render the SQL
(Jinja environment, macros, filters) and call it. The DDL, when and then SQL is rendered first, then rewritten. bigtesty test -v shows the result. Example:
https://github.com/tosun-si/bigtesty/tree/main/examples/06-production-sql.
At least one of expected / expected_file, row_count, functions per then block; they can be combined.
| Option | Default | Use |
|---|---|---|
ignore_order | true | false when the query has an ORDER BY that matters |
compare_columns | all | expected_only to check a few columns of a wide result |
ignore_columns | [] | non-deterministic columns: CURRENT_TIMESTAMP(), GENERATE_UUID() |
float_tolerance | floats computed by aggregations | |
key_columns | [] | the columns identifying a row ([featureName, day]): rows matched on them, duplicated keys reported |
The comparison is typed with the result schema: "2026-01-11 10:00:00" equals "2026-01-11T12:00:00+02:00"
for a TIMESTAMP, "1.50" equals 1.5 for a NUMERIC, RECORD and REPEATED are compared recursively. Don't
ignore date columns to work around formats. In YAML, quote the dates; only true / false are booleans.
Custom checks, when rows are not enough:
# assertion_functions/failures_assertions.py: actual and expected rows normalized with the result schema
def check_only_feature_psg(actual: list[dict], expected: list[dict]) -> None:
assert {row["featureName"] for row in actual} == {"featurePSG"}
then:
- query_file: queries/find_failures.sql
functions:
- { module: assertion_functions/failures_assertions.py, function: check_only_feature_psg }
For a large or tedious result, write the then with an expected_file that doesn't exist yet and let BigTesty
write it:
bigtesty test --update # or: pytest --bigtesty-update
It creates the missing files and rewrites the ones that don't match (inline expected rows are never touched).
Read the written rows before committing them: --update makes the current result the expected one, so check
them against the business rule, not against the SQL.
bigtesty validate # the config and all the test files, no call to BigQuery
bigtesty test -k merge # the scenarios whose ID (<file>::<name>) contains "merge"
pytest tests -k merge # same with pytest
Pitfall: don't alias a table with the name of a configured dataset (FROM x AS monitoring), it would be rewritten.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
4 skills in this plugin
/python-testsTest Python code, pipelines or tools that read or write BigQuery (jobs, services, dbt...) on an ephemeral BigQuery infra with BigTesty's BigTestyInfra in pytest or unittest, or from another language (Java / JUnit 5, Testcontainers, Go) with bigtesty infra create / destroy. Use when an integration test needs real BigQuery datasets created in a setup and deleted in a teardown, rather than testing SQL alone./setupSet BigTesty up in a project to test BigQuery SQL on real BigQuery - install it with uv, authenticate on GCP, write the bigtesty.yaml config (datasets, tables, DDL, labels, CMEK, cleanup, max_bytes_billed) and run the tests in CI (GitHub Actions, GitLab CI, Cloud Build). Use when adding BigTesty to a project, writing or reviewing a bigtesty.yaml, wiring the tests in a pipeline, or upgrading from BigTesty 0.x./troubleshootingFind why a BigTesty run fails and fix it - a failed assertion diff, an invalid config or test file (exit code 2), a GCP authentication or permission error, a location or CMEK error, a query over max_bytes_billed, a SQL reference that was not rewritten, or datasets left in BigQuery. Use when bigtesty test, pytest with BigTesty, BigTestyInfra or bigtesty infra create fails or behaves unexpectedly.npx claudepluginhub tosun-si/bigtesty --plugin bigtestyOther plugins' skills for the same job