{"id":41406766,"url":"https://github.com/portovep/dbt-testing-examples","last_synced_at":"2026-01-23T13:25:47.446Z","repository":{"id":150310780,"uuid":"602993276","full_name":"portovep/dbt-testing-examples","owner":"portovep","description":"Examples of how to implement unit, component, and contract tests for dbt data apps","archived":false,"fork":false,"pushed_at":"2025-05-18T14:23:47.000Z","size":162550,"stargazers_count":4,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-18T15:26:24.623Z","etag":null,"topics":["analytics-engineering","contract-testing","data-engineering","dbt","sql","tutorial-code","tutorial-exercises","unit-testing"],"latest_commit_sha":null,"homepage":"https://portovep.github.io/dbt-testing-examples/","language":null,"has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/portovep.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-17T11:44:14.000Z","updated_at":"2025-05-18T14:17:54.000Z","dependencies_parsed_at":"2023-10-19T23:09:16.309Z","dependency_job_id":"44cd955c-b86e-4a04-ab1a-7dc9a71a2478","html_url":"https://github.com/portovep/dbt-testing-examples","commit_stats":null,"previous_names":["portovep/dbt-testing-examples"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/portovep/dbt-testing-examples","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portovep%2Fdbt-testing-examples","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portovep%2Fdbt-testing-examples/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portovep%2Fdbt-testing-examples/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portovep%2Fdbt-testing-examples/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/portovep","download_url":"https://codeload.github.com/portovep/dbt-testing-examples/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/portovep%2Fdbt-testing-examples/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28693324,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-23T11:01:27.039Z","status":"ssl_error","status_checked_at":"2026-01-23T11:00:26.909Z","response_time":59,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["analytics-engineering","contract-testing","data-engineering","dbt","sql","tutorial-code","tutorial-exercises","unit-testing"],"created_at":"2026-01-23T13:25:46.843Z","updated_at":"2026-01-23T13:25:47.438Z","avatar_url":"https://github.com/portovep.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# dbt-testing-examples\n\n[![CD Pipeline](https://github.com/portovep/dbt-testing-examples/actions/workflows/cd-pipeline.yml/badge.svg?branch=main)](https://github.com/portovep/dbt-testing-examples/actions/workflows/cd-pipeline.yml)\n\nThis repository contains examples of how to implement real unit tests for a dbt data application by using the [dbt-unit-testing](https://github.com/EqualExperts/dbt-unit-testing) package. You can also check the articles I wrote on testing data pipelines and data products with dbt\n\n- [How to Improve The Code Quality of your Dbt Models with Unit Tests and TDD](https://medium.com/@pablo.porto/improving-the-code-quality-of-your-dbt-models-with-unit-tests-and-tdd-203ed0be791e).\n- [A Complete Guide to Effectively Scale your Data Pipelines and Data Products with Contract Testing and dbt](https://medium.com/towards-data-science/how-to-scale-your-data-pipelines-and-data-products-with-dbt-and-contract-testing-10c92ea9a443).\n\n## Features\n\n- Unit test and mocking examples with the dbt-unit-testing package\n- Katas to get started unit testing models\n- Component test examples with the dbt-unit-testing package\n- Sources contract test examples with the dbt-expectations package\n- Model contracts example with dbt 1.5\n- CI/CD pipeline example with Github Actions\n\n## Roadmap\n\n- [x] ~Add unit test examples~\n- [x] ~Add katas and improve README~\n- [x] ~Add component test examples~\n- [x] ~Add support for Github Codespaces~\n- [x] ~Add contract test examples~\n- [ ] Add data quality test examples\n\n## Sample dbt app\n\nOur sample dbt app is called health-insights. It takes weight and height data from upstream sources and calculates the metric body mass index. It follows the usual layered architecture commonly found in dbt projects.\n\n![The layered architecture of a typical dbt data app](https://miro.medium.com/v2/resize:fit:2000/0*dvpk1nU-43Mz7nEn)\n\n## Types of tests\n\nThe repository contains examples for both unit and component tests.\n\n![The usual test pyramid for an operational app](https://miro.medium.com/v2/resize:fit:800/format:webp/1*I6-e27kPOuJ9QaIgR9OwXw.png)\n\n## Katas\n\nThe repo contains two katas (small exercises) to learn how to implement unit tests for dbt models with the [dbt-unit-testing](https://github.com/EqualExperts/dbt-unit-testing) package:\n\n- [Kata 1 - Adding support for imperial units](exercises/kata1.md) ([Solution](exercises/kata1-solution.md))\n- [Kata 2 - Categorize body mass index (BMI) following WHO guidelines](exercises/kata1.md)\n\n\u003e A code kata is a software development exercise in which the focus is not on solving a task or problem, but on learning new skills and developing successful routines.\n\n## Local setup\n\nInstall dbt following the [official documentation](https://docs.getdbt.com/docs/get-started/installation)\n\nSpin up a Postgres database in a container\n\n```\ndocker-compose up\n```\n\nSetup the environment variables\n\n```\ncp .env.example .env\n```\n\nSetup the dbt profile\n\n```\ncp profiles.example.yml profiles.yml\n```\n\nInstall dbt dependencies\n\n```\ndbt deps\n```\n\nCheck that everything works\n\n```\ndbt debug\n```\n\nSeed the database\n\n```\ndbt seed\n```\n\n## Running the tests\n\nAll tests\n\n```\ndbt test\n```\n\nUnit tests\n\n```\ndbt test --select tag:unit-tests\n```\n\nComponent tests\n\n```\ndbt test --select tag:component-test\n```\n\nContract tests\n\n```\ndbt test --select tag:contract-test-source\n```\n\n## Running data quality tests (Coming soon)\n\n```\ndbt test --select tag:data-quality\n```\n\n## Setup data observability\n\nBuild Elementary models. It will create empty tables, that will be updated with artifacts, metrics and test results in future dbt executions.\n\n```\ndbt run --select elementary\n```\n\nRun the tests\n\n```\ndbt test\n```\n\nGenerate data observability report\n\n```\nedr report\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fportovep%2Fdbt-testing-examples","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fportovep%2Fdbt-testing-examples","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fportovep%2Fdbt-testing-examples/lists"}