News for hackers. Stuff that matters.
Re:Fear makes you a worse programmer by PaulStatezny on Tuesday April 09, 2024 @02:19AM (#39976613)
You need mostly integration tests, not unit tests.

Unit tests which dependency-inject mocks of other parts of your codebase are 99% worthless.

Source: Spent many years writing the latter and they caught close to 0 bugs. Moved to Elixir ecosystem where integration tests are the norm, and they catch bugs on a regular basis.

Re:Fear makes you a worse programmer by pjerem on Tuesday April 09, 2024 @03:42AM (#39977022)
In my experience, Unit tests are interesting when they are inlined with the function they test, i.e. in the same file (like python doctests). Of course it’s harder to set the testing environment but that may in fact be encouraging you to write stateless code so there is that.
Re:Fear makes you a worse programmer by rramadass on Tuesday April 09, 2024 @03:19AM (#39976915)
Bingo!

I never understood the fascination with Unit Tests. For Testing to be useful the code being tested should have a certain degree of Complexity (algorithmic/behavioural/state-transition/etc.). But what i see from most unit tests is mere "busy work" as if mock-testing a trivial class/api/etc. would somehow make your code better. A similar criticism is also applicable to TDD based programming.

Re:Fear makes you a worse programmer by hitchstory on Tuesday April 09, 2024 @04:33AM (#39977313)
The "busy work" of low level unit tests is perfectly valid, but TDD still works extremely well with high level integration tests so I don't think a similar criticism necessarily applies.
Re:Fear makes you a worse programmer by randomdata on Tuesday April 09, 2024 @02:16PM (#39982378)
> I never understood the fascination with Unit Tests.

Me neither. The legacy forms of testing that "unit" was trying to differentiate from have died out. All tests are unit tests today, which is why most developers just say "tests". "Unit" is already implied and adds no additional information not already understood by "test" alone.

Same goes for integration tests. Integration tests, as it was historically defined, died out. It seems anyone still trying to use the term today is using it to also just mean "testing", or what was historically known as unit testing. Like unit, a pointless qualification.