News for hackers. Stuff that matters.
Re:Don't Use Mocks by snorremd on Tuesday June 20, 2023 @04:10AM (#36401038)
I feel that if most of your tests relies on mocks it is a symptom of a very side-effected programming style. If you cannot unit test most your business logic then you are probably mixing up your business level code with side-effecting code (like calling APIs or DBs).

Personally I've found it better to split pure business logic and side-effecting logic as close to the edge (API endpoint handler) as possible. Then it is trivial to see where side-effects happen and you get to easily write unit tests for the business logic that matter.

Mocking is mostly always a pain and I would rather not mock at all and do proper end-to-end for integration code if possible.

Re:Don't Use Mocks by nly on Tuesday June 20, 2023 @04:22AM (#36401127)
The 'business logic' for many apps consists entirely of calling other APIs and databases.
Re:Don't Use Mocks by wickoff on Tuesday June 20, 2023 @04:30AM (#36401193)
If your database isn't involved in your business logic then you're probably significantly underutilizing capabilities of modern databases.
Re:Don't Use Mocks by krubar on Tuesday June 20, 2023 @07:25AM (#36402473)
How is that so?
Re:Don't Use Mocks by ehutch79 on Tuesday June 20, 2023 @11:09AM (#36405117)
For SQL databases at least:

You can your db sum columns faster than you can grab the data, parse it, and compute the sum. In query calculations to avoid race conditions from doing the math on separate servers, etc.

Triggers and procedures are a thing.

The nosql/kv store hype missed a lot of stuff relational/sql dbs did well. Mostly because at the time they declared sql was too hard, or just never studied anything.

Re:Don't Use Mocks by sumedh on Tuesday June 20, 2023 @07:25AM (#36402470)
> business level code with side-effecting code (like calling APIs or DBs).

Sometimes the business logic is in DBs with stored procs.

Re:Don't Use Mocks by joeblubaugh on Tuesday June 20, 2023 @07:47AM (#36402681)
That’s a whole other can of worms! The difficulty of versioning stored procedures is such a detriment to effectively using all that power.
Re:Don't Use Mocks by ehutch79 on Tuesday June 20, 2023 @11:10AM (#36405133)
They should be part of your migrations? and your migration should be versioned?