News for hackers. Stuff that matters.
Re:C++ Dev Ecosystem 2021 by bcrosby95 on Monday July 19, 2021 @07:46PM (#27888573)
> I flat-out do not use mocks for this very reason. They are intricate, involved, and take huge amounts of time to load context when they fail. Don't write such tests.

This is why I prefer integration tests. Most of my projects interact heavily with a database. Making it an integration test unless I mock it out. Which I don't do, because in my experience, doing so tends to hide lots of bugs.

Re:C++ Dev Ecosystem 2021 by titzer on Monday July 19, 2021 @08:36PM (#27888921)
> This is why I prefer integration tests.

IMO integration tests are great for making sure that your system actually functions with all its parts together. Nothing but an integration test can do that. But unit tests serve a different role: reducing the scope of the system under test so that you can pinpoint exactly what part failed when it does fail. They help you iterate quickly in refactoring, and when something goes wrong in production (or a bug report from the field), they narrow the cone of uncertainty by eliminating from consideration the parts of the system that are working correctly. In my experience, this rapidly cuts down on the amount of wild goose chases one goes on and overall makes a team more efficient. Then once a bug in the wild is found, the system responsible for the failure gets new regression tests and unit tests. Sometimes, I wrote unit tests for units I am suspicious of as I am debugging, and even if those tests don't find a bug, I might keep them.

I worked for 6+ years on V8 and the parts of the system that were the least unit tested seemed to be home to far more production issues than others.

It also helps a lot to keep your unit tests running super fast. Under 1 second is ideal.