You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/concepts/overview.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -52,7 +52,9 @@ Bad data is worse than no data. The best way to keep bad data out of your system
52
52
### [Tests](./tests.md)
53
53
SQLMesh "tests" are similar to unit tests in software development, where the unit is a single model. SQLMesh tests validate model *code*— you specify the input data and expected output, then SQLMesh runs the test and compares the expected and actual output.
54
54
55
-
SQLMesh automatically runs tests when you apply a `plan`, or you can run them on demand with the [`test` command](../reference/cli.md#test).
55
+
SQLMesh automatically runs all unit tests when a `plan` is created. Use `--test-changed-only` to run tests only for models included in the plan (added, modified, or restated), `--skip-tests` to skip, run tests for specific models with [`sqlmesh test --select-model`](../reference/cli.md#test), or run the full suite on demand with the [`test` command](../reference/cli.md#test).
56
+
57
+
Learn more in the [testing guide](../guides/testing.md).
56
58
57
59
### [Audits](./audits.md)
58
60
In contrast to tests, SQLMesh "audits" validate the results of model code applied to your actual data.
Copy file name to clipboardExpand all lines: docs/concepts/tests.md
+3-1Lines changed: 3 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,8 @@
1
1
# Testing
2
2
3
-
Testing allows you to protect your project from regression by continuously verifying that the output of each model matches your expectations. Unlike [audits](audits.md), tests are executed either on demand (for example, as part of a CI/CD job) or every time a new [plan](plans.md) is created.
3
+
Testing allows you to protect your project from regression by continuously verifying that the output of each model matches your expectations. Unlike [audits](audits.md), tests are executed either on demand (for example, as part of a CI/CD job or via [`sqlmesh test`](../reference/cli.md#test)) or when a new [plan](plans.md) is created.
4
+
5
+
By default, `sqlmesh plan` runs all unit tests. Use `--test-changed-only` to run tests only for models included in the plan (added, modified, or restated), or `--skip-tests` to run none. With both `--select-model` and `--test-changed-only`, tests run only for selected models that changed.
4
6
5
7
Similar to unit testing in software development, SQLMesh evaluates the model's logic against predefined inputs and then compares the output to expected outcomes provided as part of each test.
Copy file name to clipboardExpand all lines: docs/faq/faq.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -102,7 +102,7 @@
102
102
SQLMesh's default behavior is appropriate for most deployments, but you can override where SQLMesh creates physical tables and views with [schema configuration options](../guides/configuration.md#environment-schemas).
103
103
104
104
??? question "What's the difference between a `test` and an `audit`?"
105
-
A SQLMesh [`test`](../concepts/tests.md) is analogous to a "unit test" in software engineering. It tests *code* based on known inputs and outputs. In SQLMesh, the inputs and outputs are specified in a YAML file, and SQLMesh automatically runs them when `sqlmesh plan` is executed.
105
+
A SQLMesh [`test`](../concepts/tests.md) is analogous to a "unit test" in software engineering. It tests *code* based on known inputs and outputs. In SQLMesh, the inputs and outputs are specified in a YAML file, and SQLMesh runs all unit tests when `sqlmesh plan` is executed (use `--test-changed-only` to run only tests for models in the plan).
106
106
107
107
Writing YAML is annoying and error-prone, so SQLMesh's [`create_test` command](../concepts/tests.md#automatic-test-generation) allows you to automatically generate YAML test files based on queries of existing data tables.
Copy file name to clipboardExpand all lines: docs/guides/models.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -161,7 +161,7 @@ Reverting to a previous model version is a quick operation since no additional w
161
161
162
162
SQLMesh automatically validates your models in order to ensure the quality and accuracy of your data. This is done via the following:
163
163
164
-
* Running unit tests by default when you execute the `plan` command. This ensures all changes to applied to any environment are logically validated. Refer to [testing](../concepts/tests.md) for more information.
164
+
* Running all unit tests when you execute the `plan` command (use `--test-changed-only` to run only tests for models in the plan). This ensures changes applied to any environment are logically validated. Refer to [testing](../concepts/tests.md) for more information.
165
165
* Running audits whenever data is loaded to a table (either for backfill or loading on a cadence). This way you know all data present in any table has passed all defined audits. Refer to [auditing](../concepts/audits.md) for more information.
166
166
167
167
SQLMesh also provides automatic validation via CI/CD by automatically creating a preview environment.
Copy file name to clipboardExpand all lines: docs/guides/testing.md
+9-1Lines changed: 9 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -12,11 +12,19 @@ OK
12
12
```
13
13
As the unit tests run, SQLMesh will identify any that fail.
14
14
15
+
By default, `sqlmesh plan` runs all unit tests. Use `--test-changed-only` to run tests only for models included in the plan (added, modified, or restated), or `--skip-tests` to run none. With both `--select-model` and `--test-changed-only`, tests run only for selected models that changed.
16
+
15
17
For more information about tests, refer to [testing](../concepts/tests.md).
16
18
17
19
### Test changes to a specific model
18
20
19
-
To run a specific model test, pass in the suite file name followed by `::` and the name of the test; for example: `sqlmesh test tests/test_suite.yaml::test_example_full_model`.
21
+
To run unit tests for a specific model, use `--select-model`:
22
+
23
+
```bash
24
+
$ sqlmesh test --select-model sqlmesh_example.full_model
25
+
```
26
+
27
+
Alternatively, pass in the suite file name followed by `::` and the name of the test; for example: `sqlmesh test tests/test_suite.yaml::test_example_full_model`.
Copy file name to clipboardExpand all lines: docs/integrations/dbt.md
+5-2Lines changed: 5 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -287,9 +287,12 @@ If set to `False`, then the snapshot will be skipped and a warning will be logge
287
287
Support for this will be added soon.
288
288
289
289
## Tests
290
-
SQLMesh uses dbt tests to perform SQLMesh [audits](../concepts/audits.md) (coming soon).
291
290
292
-
Add SQLMesh [unit tests](../concepts/tests.md) to a dbt project by placing them in the "tests" directory.
291
+
dbt and SQLMesh use the word "test" differently. See [Workflow differences](#workflow-differences-between-sqlmesh-and-dbt) above for an overview.
292
+
293
+
SQLMesh converts dbt tests (singular and generic `.sql` files in the `tests/` directory) into SQLMesh [audits](../concepts/audits.md). These run against data that already exists in your tables, just like dbt tests.
294
+
295
+
Add SQLMesh [unit tests](../concepts/tests.md) to a dbt project by placing YAML files named `test*.yaml` or `test*.yml` in the `tests/` directory. Unit tests validate model query logic with predefined inputs and expected outputs; they are separate from dbt's SQL test files.
0 commit comments