Re:Unit Testing: Is There Really Any Debate Any Longer?
by kleiba on Wednesday September 12, 2012 @10:04AM
(#4510685)
...for testing.
[ Parent
| on HN ]
Re:Unit Testing: Is There Really Any Debate Any Longer?
by bryanlarsen on Wednesday September 12, 2012 @10:58AM
(#4510946)
In my experience, that clause is not required. Code that's been designed for easy testing is better code, period. Not just because it's been tested. Code designed for testing tends to have cleaner interfaces and is better modularized.
Re:Unit Testing: Is There Really Any Debate Any Longer?
by romaniv on Wednesday September 12, 2012 @12:08PM
(#4511322)
Unit testing can easily lead to arbitrary modularity or code fracturing, which makes code harder to use and reason about. Good code should be designed for solving problems, easy use and readability. If your code is designed primarily for passing code coverage checks, then it probably is not very good.
Re:Unit Testing: Is There Really Any Debate Any Longer?
by cheez on Wednesday September 12, 2012 @12:35PM
(#4511499)
It does require a degree of latitude and good judgement. This only comes from experience.
Re:Unit Testing: Is There Really Any Debate Any Longer?
by ZeroGravitas on Wednesday September 12, 2012 @10:13AM
(#4510735)
... which is just re-using your code in a slightly different context.
Re:Unit Testing: Is There Really Any Debate Any Longer?
by cheez on Wednesday September 12, 2012 @12:48PM
(#4511568)
This is generally my goal with making code testable. If I can make it modular and re-usable, that makes it much easier for me to maintain and extend in the future.
"Does this thing roughly do what I think it does?" is a secondary goal for me.
Re:Unit Testing: Is There Really Any Debate Any Longer?
by torus on Wednesday September 12, 2012 @10:17AM
(#4510759)
One way to look at it is that optimising for testing is optimising for correctness
Re:Unit Testing: Is There Really Any Debate Any Longer?
by romaniv on Wednesday September 12, 2012 @11:46AM
(#4511185)
Not always. The GP post is more insightful than it might appear. A lot of reasoning used for arguing in favor of adding more unit tests is circular. "Good code is unit testable, so unit testable code is good."
Very often, optimizing certain kinds of code for unit testing makes it significantly more complicated, with none of that complexity helping you in the actual program. This is especially true for "end user" code, such as controllers.