Click here to Skip to main content
15,921,113 members

Welcome to the Lounge

   

For discussing anything related to a software developer's life but is not for programming questions. Got a programming question?

The Lounge is rated Safe For Work. If you're about to post something inappropriate for a shared office environment, then don't post it. No ads, no abuse, and no programming questions. Trolling, (political, climate, religious or whatever) will result in your account being removed.

 
GeneralRe: Interesting piece on the fallibility of science. Pin
jschell30-Jan-14 8:06
jschell30-Jan-14 8:06 
GeneralRe: Interesting piece on the fallibility of science. Pin
PIEBALDconsult27-Jan-14 9:20
mvePIEBALDconsult27-Jan-14 9:20 
GeneralRe: Interesting piece on the fallibility of science. Pin
W Balboos, GHB29-Jan-14 4:58
W Balboos, GHB29-Jan-14 4:58 
GeneralRe: Interesting piece on the fallibility of science. Pin
PIEBALDconsult29-Jan-14 5:14
mvePIEBALDconsult29-Jan-14 5:14 
GeneralRe: Interesting piece on the fallibility of science. Pin
W Balboos, GHB29-Jan-14 5:42
W Balboos, GHB29-Jan-14 5:42 
GeneralTwo things... PinPopular
Marc Clifton27-Jan-14 5:39
mvaMarc Clifton27-Jan-14 5:39 
GeneralRe: Two things... Pin
Pualee27-Jan-14 5:49
Pualee27-Jan-14 5:49 
GeneralRe: Two things... Pin
Marc Clifton27-Jan-14 7:07
mvaMarc Clifton27-Jan-14 7:07 
Pualee wrote:
BUT... is there still a value to testing those methods which call into the simple units, or is that left to the QA department's functional testing? The underlying question here is, will that affect my code coverage metric adversly?


And that is the $20,000 question. Here's my 2c:

OK, let's say you are ultra-super disciplined and your lowest level methods don't have any conditional logic, no looping, nothing but "here are the inputs, here's the output." So that's the Holy Grail of unit testing not necessarily doable or meaningful.

The second level is that we allow some basic conditional logic and some basic looping. OK, now the unit tests are a little more meaningful and still "controllable" in that we can usually provide all the test cases to test each branch and iteration / recursion, as long as the functions are small enough.

What then? Well, can you organize your higher order functions somehow? For example, those that simply perform a workflow. It's easy enough to write a unit test that the workflow does what it's expected to do. What about more complex conditions? Those are unit testable too -- again the idea is to keep the functions small so that there aren't too many branches that need to be called. And furthermore, and most importantly, branches should not contain any statements other than a call to function to do something on that branch. No nesting, no inner looping, nothing but if-call-else-call. Rinse-and-repeat as you go up the food chain, keeping functions with conditionals and looping small, realizing that you don't need to test the lower level calls, only the higher level results.

At some point, the cost of unit tests becomes too high, which is a good time to switch over to the "if it broke, write a unit test first to recreate the problem" mode. That way, it's really cost effective -- you're fixing only known bugs and adding to your test suite.

Pualee wrote:
Unit testing seems to force you into a certain mindset when you start out the coding.


They do indeed!

Does that help?

Marc
GeneralRe: Two things... Pin
Pualee27-Jan-14 7:12
Pualee27-Jan-14 7:12 
GeneralRe: Two things... Pin
Simon_Whale27-Jan-14 5:55
Simon_Whale27-Jan-14 5:55 
GeneralRe: Two things... Pin
Marc Clifton27-Jan-14 7:08
mvaMarc Clifton27-Jan-14 7:08 
GeneralRe: Two things... Pin
jesarg27-Jan-14 6:08
jesarg27-Jan-14 6:08 
GeneralRe: Two things... Pin
Marc Clifton27-Jan-14 7:09
mvaMarc Clifton27-Jan-14 7:09 
GeneralMilitant cyclist gets punched in the face Pin
Erudite_Eric27-Jan-14 5:31
Erudite_Eric27-Jan-14 5:31 
GeneralRe: Militant cyclist gets punched in the face Pin
charlieg27-Jan-14 5:38
charlieg27-Jan-14 5:38 
GeneralRe: Militant cyclist gets punched in the face Pin
Rage27-Jan-14 5:40
professionalRage27-Jan-14 5:40 
GeneralRe: Militant cyclist gets punched in the face Pin
Duncan Edwards Jones27-Jan-14 6:19
professionalDuncan Edwards Jones27-Jan-14 6:19 
GeneralRe: Militant cyclist gets punched in the face Pin
charlieg27-Jan-14 6:26
charlieg27-Jan-14 6:26 
GeneralRe: Militant cyclist gets punched in the face Pin
Ennis Ray Lynch, Jr.27-Jan-14 6:32
Ennis Ray Lynch, Jr.27-Jan-14 6:32 
GeneralRe: Militant cyclist gets punched in the face Pin
Dan Neely27-Jan-14 9:13
Dan Neely27-Jan-14 9:13 
GeneralRe: Militant cyclist gets punched in the face Pin
CPallini27-Jan-14 6:50
mveCPallini27-Jan-14 6:50 
GeneralRe: Militant cyclist gets punched in the face Pin
Brendan Costigan27-Jan-14 7:17
Brendan Costigan27-Jan-14 7:17 
GeneralRe: Militant cyclist gets punched in the face Pin
Ravi Bhavnani27-Jan-14 7:55
professionalRavi Bhavnani27-Jan-14 7:55 
GeneralRe: Militant cyclist gets punched in the face Pin
Brendan Costigan27-Jan-14 10:20
Brendan Costigan27-Jan-14 10:20 
GeneralRe: Militant cyclist gets punched in the face Pin
Joe Woodbury27-Jan-14 7:18
professionalJoe Woodbury27-Jan-14 7:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.