0
0
dbtdata~5 mins

Custom singular tests in dbt - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a custom singular test in dbt?
A custom singular test in dbt is a user-defined check that runs a single SQL query returning zero or more rows. If the query returns any rows, the test fails. It helps validate specific data quality rules beyond built-in tests.
Click to reveal answer
beginner
How do you define a custom singular test in dbt?
You create a SQL file in the 'tests' directory with a query that returns rows when the test fails, typically named `<model_name>__<test_name>.sql`. dbt automatically runs it during `dbt test`.
Click to reveal answer
beginner
Example: What does this custom singular test do?
select * from {{ model }} where order_amount < 0
This test checks if any orders have a negative amount. If any rows are returned, it means there are invalid negative order amounts, so the test fails.
Click to reveal answer
intermediate
Why use custom singular tests instead of built-in tests in dbt?
Custom singular tests let you check complex or unique business rules that built-in tests can't cover. They provide flexibility to enforce specific data quality needs.
Click to reveal answer
beginner
Where do you place custom singular test SQL files in a dbt project?
Place them inside the 'tests' folder at the root or inside a subfolder like 'tests/custom'. This keeps tests organized and discoverable by dbt.
Click to reveal answer
What does a custom singular test in dbt return when it fails?
AOne or more rows
BNo rows
CA boolean value
DAn error message
Where should you place your custom singular test SQL files in a dbt project?
AIn the 'models' folder
BIn the 'tests' folder
CIn the 'macros' folder
DIn the root folder
Which of these is a reason to create a custom singular test?
ATo check for null values in a column
BTo enforce a unique constraint
CTo create a new model
DTo validate a complex business rule not covered by built-in tests
How do you run custom singular tests in dbt?
AUsing 'dbt test'
BUsing 'dbt run'
CUsing 'dbt compile'
DUsing 'dbt seed'
What happens if a custom singular test query returns zero rows?
AThe test is skipped
BThe test fails
CThe test passes
DAn error is raised
Explain what a custom singular test is in dbt and how it works.
Think about how dbt knows a test passed or failed based on query results.
You got /5 concepts.
    Describe the steps to create and use a custom singular test in a dbt project.
    Consider both the file location and how dbt executes the test.
    You got /5 concepts.