Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Type of Projects where Unit Testing is useless [closed]

Do you believe that Unit Testing (and test driven development) must be done under any set of circumstances or should there be some exceptions. I've been working on the type of projects lately where I can't see how Unit Testing would be useful or improve design, quality of code, etc. One type of project is PDF reports generator which takes aggregate data (values already calculated and QAed) and outputs it to a PDF report file. Another type is straight-forward CRUD applications using 3rd party ORM tool. I can see how someone could make an argument for using Unit Testing for CRUD application, but it's a lot of unnecessary and time consuming setup work, like stabbing out all the calls to a database and mocking business objects, etc. when at the end all you need to know if something happened to the DB. So when one should use or avoid Unit Testing?

Thanks

like image 655
WebMatrix Avatar asked Feb 06 '09 15:02

WebMatrix


3 Answers

  • For example writing automated tests for the user interface/presentation layer is often not worth the trouble. In that case it's often best to keep the presentation layer very thin, and have a testable layer which contains all the functionality of the presentation layer. Then the presentation layer will be mainly declarative and contain only simple glue code. When everything is declarative, there is little that can break, so testing it is not necessary. Things such as are the UI elements aligned properly, is the layout ok, are the labels right etc. are easier to test manually.

  • Throwaway code. If the code will be used only once, and it is not important that it works right, and if ever the need to modify the code arises you can afford to rewrite it, there might not be benefit from writing high quality code and tests. But when the code gets bigger, or you need to maintain it, or it is important for the code to work right, writing tests is worth the effort. I once heard somebody say that if he writes more than 10 lines of code without tests, then he begins to be unsure whether the code he just wrote will work right.

like image 121
Esko Luontola Avatar answered Sep 24 '22 09:09

Esko Luontola


To paraphrase Jeff & Joel's recent comments on the SOB: you should do unit testing when it adds value to your product.

In the two cases you describe, you would be able to do a WHOLE LOT of ad-hoc fixes (and/or post-facto regression testing) for the same cost as writing unit tests. So don't write unit tests.

like image 21
Eric Avatar answered Sep 24 '22 09:09

Eric


"I once heard somebody say that if he writes more than 10 lines of code without tests, then he begins to be unsure whether the code he just wrote will work right."

This person is a danger to his or her self. Remove them from the code immediately.

like image 39
anon Avatar answered Sep 23 '22 09:09

anon