Back to articles
Notes on Testing: Why I Prefer Testcontainers Over Mocks
NewsDevOps

Notes on Testing: Why I Prefer Testcontainers Over Mocks

via Dev.toAsaduzzaman Pavel

I've wasted entire Fridays writing "perfect" mocks for my database layer. I'd spend hours defining exactly what GetByID should return, only to have the app crash in production because of a missing comma in my SQL or a misunderstood Postgres constraint. That's the problem: mocks don't test your code, they test your assumptions about your code. And usually, your assumptions are wrong. ...And that's why I've mostly moved to Testcontainers. I'd rather wait ten seconds for a real Docker container to spin up than spend ten minutes faking a database behavior that I'm only 80% sure about anyway. Mocks are just lies we tell ourselves When you mock a database repository, you're essentially saying: "When I call GetByID , return this static struct." It's fast, sure, but it completely ignores reality. It doesn't catch syntax errors, it doesn't catch unique constraint violations, and it definitely doesn't catch the weird way your specific version of Postgres handles JSONB columns. I've seen too many

Continue reading on Dev.to

Opens in a new tab

Read Full Article
2 views

Related Articles