CodeBetter.Com
CodeBetter.Com
RSS 2.0 via Feedburner
           Do you Twitter? Follow us @CodeBetter

Darrell Norton's Blog [MVP]

Fill in description here...

Where does unit testing fail?

From an old ADT interview, Mike Gunderloy is asking the questions and Mike Clark is answering.

(Mike Gunderloy) Q: Now that we've got some reasonable experience with unit testing, where do you think it fails?

(Mike Clark) A: I think unit testing fails when we use it as a substitute for acceptance testing. That is, unit tests that pass don't tell us that we built the right thing. They only tell us that what we built works as we, the programmers, expect. So as much as I'm encouraged by the enthusiasm for test-driven development and unit testing, I think we have to start putting an equal amount of emphasis on acceptance testing.

I also see unit testing failing in cases where it's a checkbox item on a project schedule. Just saying that we're doing unit testing says nothing about the quality of the tests. So I like to see a test fail once in a while as it tells me that the test is actually testing something that could break. I also like to open the tests up to review by users of my code and folks with more testing experience to see where I might improve the quality of the tests.

Finally, a common question I hear revolves around what to do about legacy code on a project that doesn't have unit tests. It frightens me to hear that some managers want to get to a certain percentage of test coverage for all legacy code. Unit testing legacy code can be successful if done tactically around sections of code undergoing change or containing bugs. But when unit testing is taken as an all-or-nothing approach, it's neither practical nor economical.

[via Mike Clark's weblog]


Published May 04 2005, 12:40 PM by darrell
Filed under: ,

Comments

Jeremy MIller said:

Nice post. I've gotten into trouble before putting too much faith in the unit test coverage. I think true acceptance tests by real testers are a no brainer.

I'd also add an intermediate level of developer testing that tests partial integrations of the codebase and get this into your build. I'm usually pretty aggressive about mocking the database or the UI in unit tests, but that can let integration bugs get through the unit test safety net.

There's a school of thought that says if the unit testing coverage is good enough, integration testing is superfluous. My painful experience says otherwise.
# May 4, 2005 7:46 PM

Lorenzo Barbieri @ UGIblogs! said:

# May 5, 2005 4:37 AM

darrell said:

Joriveek - bad communication will almost always set a project up for failure, testing-wise or coding-wise, etc.
# May 5, 2005 11:56 AM

darrell said:

Jeremy - agreed 100%.
# May 5, 2005 11:57 AM

Geek Noise said:

# May 9, 2005 9:06 AM
Check out Devlicio.us!