A template test is one test definition that Validatar applies to every table or column you select. You write the check once, Validatar creates a separate child test for each table or column, and every child runs and reports on its own.
Template tests are how teams test hundreds or thousands of tables without writing hundreds or thousands of tests.
A worked example
Say you load 49 tables from an order system on SQL Server into a Snowflake warehouse every night. You want to know, for every table, that the warehouse has the same number of rows as the source.
As standard tests, that is 49 tests to build and 49 tests to maintain. When the order system adds a 50th table, someone has to remember to add a 50th test.
As a template test, it is one test. You write the row count query once, with variables where the schema and table names go:
-- Rows in the source table
SELECT COUNT(*) AS row_count
FROM [{{schema.name}}].[{{table.name}}]
Then:
- Compare it to the same count in the warehouse, the way you would in a standard test.
- Choose which tables the template covers. Here it is every base table in the order system, across all of its schemas: 49 tables.
- Materialize the template. Validatar creates 49 child tests, one per table, each with the real schema and table name filled in.
- Add the template to a job with Materialize child tests turned on. When the 50th table shows up in the catalog, the next job run creates its child test and runs it. Nobody has to remember.
When a child test fails, it fails on its own, with its own result and history. You see "Sales.Orders does not match" rather than "something in the order system does not match".
How a template test works
| Part | What you decide |
|---|---|
| Test definition | The check itself: data set, what to compare to, and the result criteria. It is built like a standard test, with variables such as {{schema.name}}, {{table.name}} and {{column.name}} where the object name goes. |
| Target object type | Table creates one child test per table. Column creates one child test per column. |
| Where the list of objects comes from | Metadata Driven selects tables or columns from the catalog with filters. Metadata Script runs a query or script that returns the list. Import File reads the list from a spreadsheet you upload. |
| Child test configuration | How each child test is named and which folder it goes in. |
| Materialize | Creates, updates or removes child tests to match the current template and object list. |
Which source to use
| Source | Use it when | Example |
|---|---|---|
| Metadata Driven | Everything you need is already in the catalog: schema, table and column names, data types, custom field values | Row counts for every table in a schema; a null check on every column marked as a key |
| Metadata Script | The list comes from somewhere else, or each object needs extra values a query can supply | Pair each staging table with its warehouse table using a mapping table |
| Import File | A person maintains the list, or each row carries its own settings | A business rules spreadsheet where each row has a table, a rule and a tolerance |
Values you supply with a Metadata Script or an Import File reach the test definition as {{var.name}} variables, such as {{var.tolerance}} or {{var.target_table}}.
Materializing child tests
Materializing is the step that turns the template into child tests. Nothing runs until you materialize.
- The first time, Validatar shows how many child tests it will create and where they will go.
- After you change the template, materialize again so the children pick up the change. Child tests that nobody has edited are updated automatically when you choose Update all non-customized child tests. Child tests that someone edited by hand are customized, and they are only replaced if you choose Overwrite all customized child tests.
- When objects leave the selection, for example a table is dropped, choose Delete all child tests for objects no longer selected in metadata to remove their child tests.
- In a job, a template test step or folder step can materialize before it runs, so the child tests always match the current catalog.
For the dialog options in detail, see Materializing Child Tests.
Standard test or template test?
| Use a standard test when | Use a template test when |
|---|---|
| You are checking one specific table, column or business rule | The same check applies to many tables or columns |
| The SQL is unique to that one object | Only the object names or a few values change from one object to the next |
| You are exploring and the check will change often | You want new tables to be covered without anyone adding tests |
A common path is to build and prove a standard test on one table, then turn it into a template once it works.
Do it with Validatar AI
Tip: On Validatar Cloud, the Validatar AI chat (beta) can create a template test for you. Open the chat and ask, for example: "Create a template test in the Wholesale project that compares the row count of every table in the Sales schema with the same table in the warehouse." Review the template it creates before you materialize it. The AI cannot materialize or run a template, so do that step on the template's page. You can undo the AI's change from the chat history.
Engineers who work in a coding agent can use the Validatar Agent Kits to build template tests and the files that feed them.
Next steps
- Select tables and columns from the catalog: Select Tables and Columns for a Template Test (Metadata Driven)
- Build one step by step: Create a Template Test
- Drive a template from a spreadsheet: Generating Child Tests from an Import File
- Drive a template from a query: Generating Child Tests using a Metadata Script
- Copy a working example: Template Test Examples: Import File and Template Test Examples: Metadata Script
- Reconcile source and target tables at scale: Reconciling Source and Target with Key-Based Templates