In my experience the usefulness of Unit Tests is very dependent on the quality of the team and its grasp on the business requirements. Some programmers can write high quality code that doesn't need unit/integration testing at all, some can't.
Legacy code = code without tests. You might write HQ code today, but without tests it'll become technical debt within a month or even a week down the line. Programmers come and go, unit tests are omnipresent.
Why Most Unit Testing Is Waste [pdf]
11–20 of 159 posts
Re: Why Most Unit Testing Is Waste [pdf]
#12I pretty much agree with all of this. Unit tests are great when you have a large code base with dozens of apps and need to modify a core library to remove side effects. How do you know you didn't break one of the apps? But if we go deeper, why does the core library have side effects? Because it was a crummy, poorly designed piece of crap to begin with. If it was originally written with high quality it wouldn't need t…
It's easy to disagree with someone who portrays an enemy which doesn't exist.
I disagree with this piece everywhere it manages to land somewhere concrete, where its claims can be verified and assessed.
> But if we go deeper, why does the core library have side effects
Let's not get ahead of ourselves in theoretical, non-applied functional programming.
As even Haskellers recognize, all computing would be meaningless if there ultimately was no side effects. In fact, we use computers for their "side-effects".
Sometimes you need side-effects. And sometimes you unit-tests are great way of automatically verifying that you have the right side-effects.
Re: Why Most Unit Testing Is Waste [pdf]
#13Despite the inflammatory title, the point the PDF is making I believe is that unit tests should be kept short and simple, and convey the intent of your code.
Intent is akin to the 'why' - written code explains the 'how' and 'what' extremely well, but without the 'why' it loses all meaning. Writing tests to convey intent is essential because no computer or programming language can do this for us currently, so it's left up to us.
Re: Why Most Unit Testing Is Waste [pdf]
#14The normal practice for large scale codebases in complex domains is "the code is the spec". That is, the only specification for how the system should work is how it worked yesterday. In that case, unit tests serve as a great specification. Even tests that just duplicate the business code under test and assert that it's the same (A huge waste in normal cases) is useful. Because a Unit test is much better than a word d…
We tend to put a high value on code review, yet some don't value unit testing. Lean in and I'll tell you a secret:
... unit testing is automated, repeatable, code review!
Re: Why Most Unit Testing Is Waste [pdf]
#15Earlier quoted context omitted.
Legacy code = code without tests. You might write HQ code today, but without tests it'll become technical debt within a month or even a week down the line. Programmers come and go, unit tests are omnipresent.
All code is legacy code as soon as you type the semi-colon. It is wishful thinking that a suite of unit tests will prevent a refactor or small change from producing technical debt.
Re: Why Most Unit Testing Is Waste [pdf]
#16In my experience the usefulness of Unit Tests is very dependent on the quality of the team and its grasp on the business requirements. Some programmers can write high quality code that doesn't need unit/integration testing at all, some can't.
Legacy code = code without tests. You might write HQ code today, but without tests it'll become technical debt within a month or even a week down the line. Programmers come and go, unit tests are omnipresent.
Re: Why Most Unit Testing Is Waste [pdf]
#17I disagree: https://henrikwarne.com/2014/09/04/a-response-to-why-most-un...
I agree in principle, but IME:
* This kind of algorithmic code often makes up a fairly small proportion (~5%) of code written for most business driven applications - it's usually mostly coordination. Some domains may be different (and for them, unit testing will appear to be much more effective), but I think this is the norm.
* Integration tests can test algorithmic acceptably well, but unit tests do not test integration code in an acceptable fashion.
* Where you have algorithmic and integration code smushed together (this type of technical debt is, sadly, the norm 'in the wild'), again, integration tests work acceptably well whereas unit tests require a mess of mocks.
* Integration tests do not have to be high level or slow.
"Refactoring breaks tests. Sometimes when you refactor code, you break tests. But my experience is that this is not a big problem. For example, a method signature changes, so you have to go through and add an extra parameter in all tests where it is called. This can often be done very quickly, and it doesn’t happen very often. This sounds like a big problem in theory, but in practice it isn’t."
This is a big problem in practice when you are working on large scale code bases in which the developers have not been super strict about decoupling everything.
Re: Why Most Unit Testing Is Waste [pdf]
#18A lot of us would consider SQLite to be high quality and relatively bug-free. The extensive test suite they've built up that exercises each release is a huge reason for it.
Of test code quantity, Coplien writes:
>If your coders have more lines of unit tests than of code, it probably means one of several things. They may be paranoid about correctness; paranoia drives out the clear thinking and innovation that bode for high quality.
> - Keep regression tests around for up to a year
> - Throw away tests that haven’t failed in a year.
SQLite appears to keep their tests. Somebody files a bug; SQLite writes a test that reproduces that bug; the test code remains long after the bug is fixed. This prevents the bug from reappearing. (Isn't that the main purpose of "regression" in the phrase "regression test"?)
I also think it's better to keep relevant regression tests for years. E.g. Consider that there's piece of code that's been working correctly for 5 years with 5 years of passing regression tests . Imagine a new programmer wants to rewrite the code to optimize it for speed and reduced memory usage. I think we'd feel much more confidient if the new code passes those same regression tests that were accumulated over 5 years.
As for test code size ratio... A lot of good comprehensive tests will have LOC outnumbering the actual code being tested. This is especially true for library code that's used in many places up the stack. I wrote string parsing routines and a reverse Boyer-Moore search routine where the test code (test edge cases, test nulls, test string sizes at 2^32 boundaries, etc) was 10 times larger than the actual code.
Of testing's utility, Coplien writes:
- Testing can’t replace good development
- [...] Tests don’t improve quality: developers do
... which looks like a strawman and a false dichotomy. Can anyone cite a credible development philosophy that believes testing can replace bad developers or bad process?We could say that about such that can't replace quality developers. Garbage Collection doesn't improve quality, developers do. Array boundary checking doesn't improve quality, developers do. And so on.
Or maybe there's a difference in terminology? I wonder if Coplien considers SQLite testing "system test" or a "unit test"? Does he consider SQLite "white box testing" or "black box testing"?
Re: Why Most Unit Testing Is Waste [pdf]
#19The normal practice for large scale codebases in complex domains is "the code is the spec". That is, the only specification for how the system should work is how it worked yesterday. In that case, unit tests serve as a great specification. Even tests that just duplicate the business code under test and assert that it's the same (A huge waste in normal cases) is useful. Because a Unit test is much better than a word d…
Unit tests are better than nothing, but integration tests usually serve as a better specification still.
Unit tests are ok at specifying low level side-effect-less modules though.