Live data from Hacker News

How to test without mocking

amazingcto.com

221–225 of 225 posts

Re: How to test without mocking

#221
post #177

Earlier quoted context omitted.

One of the nice things about the .NET ORM EntityFramework is that you can swap a mocked in-memory database for your prod DB with dependency injection, so without modifying your code at all and theoretically without affecting the behavior of the ORM. Which is to say, you're right, it's about using the right tools. Those tools of course vary by ecosystem and so in some cases mocking the database is in fact the correct…

Probably the single most obnoxious production defect I ever found related to a database would never have made it into production if we had been using a real database instead of a test double. It happened because the test double failed to replicate a key detail in the database's transaction isolation rules. After figuring it out, I swapped us over to running all the tests that hit the database against the real databas…

I already don't trust ORMs; ORM with fake DB sounds even worse.

Re: How to test without mocking

#222
post #146
post #42

Earlier quoted context omitted.

You have to mock/fake when modules call dependencies. Your way means you only ever have siblings. With an orchestrator pulling results out of one module and pushing it into another.

Code that uses hexagonal architecture/dependency inversion requires less mocks in their tests.

I use that architecture. You still use mocks at the edges.

Re: How to test without mocking

#223

Your mock object is a joke; that object is mocking you. For needing it. ~ Rich Hickey

Don’t really care about advice from the guy who invented an incredibly non pragmatic programming language. I also honestly had to look up who he was. So his sage advice hasn’t brought him much fame.

Re: How to test without mocking

#224
post #130

I tell my developers that each mock you use costs you $100. Maybe it is worth it, but probably not. No I don't really charge em – but it gets the idea across that mocks have costs that you don't always see up front.

Maybe you’re writing them incorrectly then? I’ve written several that were for core app features used in 30ish test cases on a team with 7 engineers and they’ve worked flawlessly for over two years.

Re: How to test without mocking

#225
post #130

I tell my developers that each mock you use costs you $100. Maybe it is worth it, but probably not. No I don't really charge em – but it gets the idea across that mocks have costs that you don't always see up front.

Maybe you’re writing them incorrectly then? I’ve written several that were for core app features used in 30ish test cases on a team with 7 engineers and they’ve worked flawlessly for over two years.

No, it is that mocks can hide interface changes. So if you have a mock, then you need to test that the interface works without the mock. And if you are doing that, why not just skip the mock?

foo calls x(user, date) foo mock # tests pass

x changes to x(user, time)

but the tests for foo do not change, tests still pass, runtime errors.

If you have static/strong typing the compiler will pick this up – but for dynamic languages you have a problem.

Post reply on HN