Skip to content

Testing

One Specification, Two Targets

Mocking a repository in tests does not verify your query; it only verifies that the method was called. Run a real database instead and the test suite slows to a crawl, so you run it less often. Either way, your filter logic ends up duplicated: once in the production code that hits the database, once in the mocks that bypass it. The two drift apart silently until a bug ships to production.

Do your unit tests depend on the system clock?

Testing code that uses new DateTime('now') or time() is painful. You end up mocking native functions, or accepting fragile tests that fail at midnight.

Direct dependency on a concrete implementation causes the same kind of problems for the logger, the cache, or the ID generator...