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…
How to test without mocking
221–225 of 225 posts
Re: How to test without mocking
#222Earlier 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.
Re: How to test without mocking
#223Your mock object is a joke; that object is mocking you. For needing it. ~ Rich Hickey
Re: How to test without mocking
#224I 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.
Re: How to test without mocking
#225I 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.
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.