All the unit tests are suddenly rendered useless. Some test code may be reused but all in all the entire test suite has to be rewritten. This means that unit tests increase maintenance liabilities because they are less resilient against code changes. Coupling between modules and their tests is introduced!
Unit testing is a waste of time, but it's a good way to test your code. You'll have to do it manually, and it's not always easy to fix problems. Testing is a way of getting things right, but you'll get stuck in testing time and have to deal with the problem.
Limitations of Unit Testing Unit testing cannot detect integration or interfacing issues between two modules. It cannot catch complex errors in the system ranging from multiple modules. It cannot test non-functional attributes like usability, scalability, the overall performance of the system, etc.
They advocate using end-to-end tests exclusively and view unit tests as restrictive to evolving the system, requiring too much time and effort to refactor, or redundant, given that the overall behaviors of the system are verified by end-to-end tests.
In my experience, there are a couple of factors involved in this:
Naturally, there are other factors, but those are just what I've run into so far.
1) It's hard
2) It takes time
3) It's very hard to determine the value of test code
Point 3 is a sticky one. Good unit tests reduce bugs. But so does good production code. How do you determine how many bugs don't exist because of your unit tests? You can't measure what does not exist. You can point to studies, but they don't fit nicely on your business manager's spreadsheet.
It is easy to put all the blame on “management.” But is management really telling you to specifically not do any unit testing?
Management in general does not (and probably should not) tell you how to do your job, whether it is modularization, abstract data types, design patterns, or unit testing. These are tools of trade that a successful, competent software engineer applies, but a poor engineer does not.
I think the real answer to your question is: unit testing is really difficult, and computer-science students are not trained for it.
It's easy when you are writing your own string class. When you are testing a real-life product, you run into challenges that nobody told you about in the powerpoint slides:
The one thing that we can blame management for is that requirement specifications rarely contain any requirements on quality level of the deliverable.
The next time your boss asks you to do a time estimate, include the time for writing a unit test and see what happens.
Most tests don't test anything.
You write a fileopen() function and a unittest that fails if the file doesn't exist and succeeds if the file does exist.
Great! Now did you check if it works with the filename in BIG5 chinese? on an NFS share? on vista with the file on a USB key and UAC turned ON?
The problem is that the unit tests are written by the same programmer who wrote the function, to the same set of assumptions and with the same level of skill. To really work the tests must be written by someone else, only to the published specs without them seeing the code. - In most companies just getting written specs would be a breakthrough!
Unit tests check for errors in the code of individual functions. They can work for data access layers, maths libraries etc where the inputs/outputs are well known and the internal structure is complex but for a lot of cases they are just a waste of time.
They fail when the errors are due to interactions between different parts of code or with the OS and the user. Problems like high/low DPI settings messing up a dialog box or a foreign language setting swapping a '.' and ',' aren't usually found.
There have been studies done on the ROI of unit tests - see this question.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With