Types of Custom Tests
dbt supports two main types of custom tests:Singular Tests
Singular tests are SQL queries that should return zero rows when the test passes:Creating Generic Custom Tests
Generic tests are more powerful because they can be applied to different models throughout your project. They are defined as macros with a special syntax:Combining Macros and Tests
You can use macros within your custom tests to create powerful, reusable testing frameworks:Advanced Test Configurations
You can configure how tests behave using additional properties:Testing Data Quality with Packages
Popular packages like dbt-expectations extend dbt’s testing capabilities with advanced data validation:Real-World Custom Test Examples
Date Range ValidationBest Practices for Custom Tests
Pro Tip: Troubleshooting Failed TestsWhen tests fail, use these strategies to diagnose issues:
- Check error messages in the dbt logs
- Examine a sample of failing records with
store_failures: true - Verify test logic by inspecting the compiled SQL in
target/compiled/ - Use
--varsto test with different parameters