News for hackers. Stuff that matters.
Re:Unit Testing is Overrated (2020) by goto11 on Thursday April 07, 2022 @01:14PM (#30947473)
> Hundreds of lines of mock code

Mocking should be kept to a minimum and ideally avoided.

Mocking is most useful when adding tests to legacy code, but new code should be designed so it can be tested without the need for mocking.

Re:Unit Testing is Overrated (2020) by older on Thursday April 07, 2022 @05:01PM (#30950302)
Mocking own code should be avoided if possible, but it does not apply to external resources like database, http responses etc.
Re:Unit Testing is Overrated (2020) by simonw on Thursday April 07, 2022 @10:33PM (#30952721)
I don't think it's ever a good idea to mock a database. Invest in a test framework that can performantly spin up a fresh database instance and throw it away at the end of the test run instead.

Mocking outbound HTTP calls is worthwhile, but thankfully most testing frameworks I've used (at least in Python world) make that pretty easy.

Re:Unit Testing is Overrated (2020) by older on Friday April 08, 2022 @01:55AM (#30953754)
I mock database by using sqlite in-memory database. It is not 100% compatible with my production database but still god enough for most of my tests. This way I have fresh database for each unit test and the tests are still fast.
Re:Unit Testing is Overrated (2020) by adhesive_wombat on Thursday April 07, 2022 @04:19PM (#30949857)
Also can be pretty handy when there's hardware that needs something very specific to happen to work properly. Mocks can give you (some) confidence that when you poke the I2C bus, you won't hang it up.

But it's very easy to overdo it and end up testing irrelevant implementation details instead.