dbt tests are unit tests for your beliefs

A software engineer friend once asked me what dbt tests actually test, since there’s no code in a unique check. Fair question. My answer took a while to arrive at: they don’t test code. They test beliefs.

Every model you build rests on assumptions you barely notice making. Order IDs are unique. Every order belongs to a customer that exists. Status is one of five known values. Amounts are positive. The upstream sync runs before ours. You believe all of this the way you believe the floor will be there when you step, and you’re right, until an upstream team ships something on a Thursday and you’re not.

The point of the test is not the day you write it, when it obviously passes. The point is the anonymous future day when reality stops matching your model of it. Without the test, that day announces itself as a weird number in a dashboard, discovered by someone else, at the worst possible time. With it, the day announces itself as a red build with a name attached.

Some things I’ve settled on after a couple of years of this:

Test at the boundaries hardest. Sources you don’t control deserve the most suspicion. My raw-layer staging models carry the strictest checks; by the time data reaches marts, it’s already been frisked.

not_null and unique do most of the work. The fancy stuff (distribution checks, anomaly thresholds) has its place, but the majority of real incidents I’ve caught were a null where one had never been, or a duplicate where one was impossible.

A test that fails must block the publish. This is the part teams chicken out on. A warning that data quality dropped is a Slack message everyone learns to scroll past. A blocked deployment is a decision someone has to make. We wired ours so failed checks stop bad data before any dashboard sees it, and the accuracy gains (roughly 88% to 98% where I measured it) came from the blocking, not the checking.

And delete tests for beliefs you no longer hold. A permanently-skipped test is documentation that lies.

Write down what you believe. Let the machine tell you when you’re wrong. It beats the alternative, which is everyone else finding out first.