A unit test shouldn’t: 🚫 Call a DB 🚫 Run a browser 🚫 Make an HTTP call 🚫...


A unit test shouldn’t:

🚫 Call a DB
🚫 Run a browser
🚫 Make an HTTP call
🚫 Rely on stuff on other machines

A unit test should pass without a network connection.

There’s nothing wrong with doing such things in a test. But if a test does these things, it’s not a unit test.
One more thing:

The definition of "unit test" matters.

Why? It gives us a clear goal.

A unit test's goal: Test in isolation, quickly.

Other types of tests like integration, end-to-end, performance, etc, are useful too. But they have different goals.
Some said "I just care about fast vs slow tests."

The problem is, "fast vs slow" is imprecise.

Some may think a DB call is fast. It's not. It's much slower.

So, specifying what a unit test *shouldn't* do helps assure the test is fast, isolated, and reliable.

View original on X