Hacker News new | ask | show | jobs
by marginalia_nu 840 days ago
Seems like such a test would be strictly less useful than a test that runs against the real dependeny.
2 comments

But vastly faster.

A good rule of thumb for a unit test is that you should be able to run it a few thousand times in a relatively brief period (think: minutes or less) and it shouldn't ever fail/flake.

If a unit test (suite) takes more than a single digit number of seconds to run, it isn't a unit test. Integration tests are good to have, but unit tests should be really cheap and fundamentally a tool for iterative and interactive development. I should be able to run some of my unit tests on every save, and have them keep pace with my linter.

Testcontainers don't typically add more than a few seconds to a suite though. They are very fast.
Then don't do it in unit tests and write an integration test.