tags:

views:

226

answers:

11

I can often identify plenty of areas which are nicely encapsulated and easily unit tested, but I also find that a lot of code where unit testing doesn't really seem to work as well - typically data access and user interface. No matter what unit testing "techniques" I try I tend to find that in these places it's not only a lot of effort to create functioning unit tests, but these tests tend to be very fragile and don't really test very much.

At what point do you stop and decide that the benefits of unit testing isn't worth the cost?

A: 

When there isn't time in the project plan for it and time is being spent finding ways of testing rather than working towards the goal of the project.

DeletedAccount
This would make greater delays in the near future.
Umair Ahmed
That's when things like deadlines and targets come into play. Hence "When there isn't time in the project plan for it"
DeletedAccount
-1. Having no time in the project plan should mean that you negotiate either Time, Cost or Scope with the stakeholders - not cut down on Quality. I'd rather have fewer things with good quality than everything that doesn't work most of the time.
Gishu
Easier said than done imo.
DeletedAccount
-1 for saying there is no time in a project. Cut out other testing rather than unit testing
AutomatedTester
Tbh, I'd rather lose a unit test than a QA Test or UAT Test. A bit of code can run beautifully and never fail, but not do what was required.
DeletedAccount
My opinion seems to be a huge dividing point, but I believe it's the same as "When you can provide better value by doing something else.". Nevermind. :o)
DeletedAccount
Isn't that quite often the problem with poor-to-rejection quality in projects, because no time was ever allocated for formulate a good testing regime?
icelava
A: 

If you have the access to some live data you can use it to unit test. also u can use data generators and random data. Unit tests only give you some level of confidence that it wont create problems in the future. If you are confident with your testing you can discontinue unit tests

Umair Ahmed
+3  A: 

I tend to test only the model and data persistence. testing the model is mandatory. UI (desktop application, webapps, command-line interface, etc) is hard to test, so I write test for it only in rare circustances.

dfa
+7  A: 

When you can provide better value by doing something else.

tomjen
+1 - Prioritize by Business value
Gishu
+1, no better definition, but really hard to evaluate..
Clement Herreman
A: 

I like the title of the question. Apart from that I think it is a dupe of Is there such a thing as excessive unit testing?

Gishu
A: 

I would say when you've gained an acceptable level of confidence. Also, like for my project at work, we are under such tight time requirements that I really have to only test certain parts of code (not all of it) just to give me a good confidence level.

jbu
+2  A: 

Usually I only test the model and the controller. Unit test are hard to apply for UI, usually i prefer manually test the app.

If creating these test cost more time than manually test everytime you might have a regression, then the test is useless (easy to say, but not to evaluate...).

Clement Herreman
+1  A: 

If you need to cut out testing, cut out integration or end-to-end testing. Misko Hevery at Google explains it really well here.

"Unit Testing gives you more bang for your buck"

is the best quote to come out of his article.

Other than that, when you have decent code coverage and are handling a few edge cases of your code then its a good time to stop unit testing.

AutomatedTester
A: 

As far as data access testing goes have you tried mock tests to simulate responses.

Duncan
A: 

The basic rule of thumb i'd follow is if the effort to build the unit test is more than the effort to repeatedly manually test the feature by human work.

If you look at the Test projects in the Visual Studio Team edition for Testers, there is such an item called a "Manual Test" which is essentially an instruction document to tell a human how to carry out the test and manually pass it. Certain things, like you mention UI testing, or code to workaround obscurely odd or buggy hardware behaviour in the underlying framework or OS or driver, are better verified by human eyes.

icelava
A: 

If you are using TDD, then you stop unit testing when all the tests in the test list have succeeded.

Otherwise, you stop unit testing when the cost of finding more bugs through unit testing exceeds the cost of finding them through your QA process. and when you've reached an acceptable level of code coverage through the combination of all tests.

John Saunders