Ask HN: How do you test SQL?
1–10 of 322 posts
Re: Ask HN: How do you test SQL?
#2For my own use-cases, I usually test this at the application level and not the DB level. This is admittedly not unit-testing my SQL (or stored procs or triggers) but integration-testing it.
Re: Ask HN: How do you test SQL?
#3This is easier if you have the same input every time the tests run, like a frozen database image, because then you can basically have snapshot tests.
Re: Ask HN: How do you test SQL?
#4You can hook up dbt tests to your CI and Git(hub|lab) for data PRs.
Depending on your needs, you can also look into data observability tools such as Datafold (paid) or re_data (free)
Re: Ask HN: How do you test SQL?
#5Re: Ask HN: How do you test SQL?
#6Excellent question. Not sure why it's getting no traction. For my own use-cases, I usually test this at the application level and not the DB level. This is admittedly not unit-testing my SQL (or stored procs or triggers) but integration-testing it.
Re: Ask HN: How do you test SQL?
#7A ref() concept like dbt's is sufficient. When testing, have ref output a different (test-x) name for all your references.
Re: Ask HN: How do you test SQL?
#8Here's [2] a slide deck by David Wheeler giving an introduction into how it works.
[2] https://www.slideshare.net/justatheory/unit-test-your-databa...
Re: Ask HN: How do you test SQL?
#9Gitlabs has their guide up, I love it and use it all the time. I've been doing data engineering in a small team for about 4 years, helping hospitals with data and hopefully making it easier to understand. Something that is overlooked or undervalued in my opinion, have stark distinctions for separating out technical and business logic tests. It makes it easier communicating what's happening in the event something is '…
Re: Ask HN: How do you test SQL?
#10Excellent question. Not sure why it's getting no traction. For my own use-cases, I usually test this at the application level and not the DB level. This is admittedly not unit-testing my SQL (or stored procs or triggers) but integration-testing it.
With ORMs you can get pretty close to this being unit testing for the DB though.