Click here to Skip to main content
15,885,546 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.

 
QuestionRe: Unit tests Pin
CPallini14-Jan-23 22:16
mveCPallini14-Jan-23 22:16 
GeneralRe: Unit tests Pin
PIEBALDconsult15-Jan-23 4:16
mvePIEBALDconsult15-Jan-23 4:16 
GeneralRe: Unit tests Pin
Richard Andrew x6415-Jan-23 11:36
professionalRichard Andrew x6415-Jan-23 11:36 
GeneralRe: Unit tests Pin
PIEBALDconsult15-Jan-23 13:37
mvePIEBALDconsult15-Jan-23 13:37 
GeneralRe: Unit tests Pin
englebart15-Jan-23 5:15
professionalenglebart15-Jan-23 5:15 
GeneralRe: Unit tests Pin
PIEBALDconsult15-Jan-23 5:59
mvePIEBALDconsult15-Jan-23 5:59 
GeneralRe: Unit tests Pin
jschell15-Jan-23 8:33
jschell15-Jan-23 8:33 
GeneralRe: Unit tests Pin
Jeremy Falcon15-Jan-23 8:45
professionalJeremy Falcon15-Jan-23 8:45 
Just so you know, I'm not hardcore TDD or BDD evangelist. I think it's ok to not write your tests first as you figure stuff out and get a feel for the app. But, make no mistake... I 100% believe there should be at least unit tests in a project. You wanna make the argument that a functional test may or may not be required... cool ok. But, nowhere under the sun should a project not be covered with unit tests.

Ahem, now with that out the way. To actually address your question... Smile | :)

It depends. Is your function a pure function? If it's using temp storage or an external dependency (resource, not lib), it's not. Typically, I design my unit tests to say f(x) == f(x) for pure functions. In your case I would not. I'd still make sure the tests always pass and are about to allocate resources (mocked or otherwise), but I wouldn't assume X in always equals X out. I would make sure the unit tests around that function handle all error scenarios however.

If you have "pure" logic that you must test inside that routine, then and only then would I mock the external resource inside the routine and test just the logic itself with f(x) == f(x) in mind. For the rest of the test coverage on that routine you can do it the non-pure way.

It's dancing around it though since technically it's not a pure function, but at may at least give you the best of both worlds in this instance.
Jeremy Falcon


modified 15-Jan-23 15:25pm.

GeneralRe: Unit tests Pin
PIEBALDconsult15-Jan-23 10:00
mvePIEBALDconsult15-Jan-23 10:00 
GeneralRe: Unit tests Pin
Jeremy Falcon17-Jan-23 3:46
professionalJeremy Falcon17-Jan-23 3:46 
Generalworldle358 Pin
jmaida14-Jan-23 10:49
jmaida14-Jan-23 10:49 
GeneralQM + AI = oo Pin
BernardIE531714-Jan-23 3:53
BernardIE531714-Jan-23 3:53 
GeneralRe: QM + AI = oo Pin
Mike Hankey14-Jan-23 5:11
mveMike Hankey14-Jan-23 5:11 
GeneralRe: QM + AI = oo Pin
jmaida14-Jan-23 16:59
jmaida14-Jan-23 16:59 
GeneralRe: QM + AI = oo Pin
BillWoodruff16-Jan-23 20:35
professionalBillWoodruff16-Jan-23 20:35 
GeneralRe: QM + AI = oo Pin
BernardIE531716-Jan-23 20:58
BernardIE531716-Jan-23 20:58 
GeneralIs "New Year; New Me" ... Pin
OriginalGriff14-Jan-23 0:24
mveOriginalGriff14-Jan-23 0:24 
GeneralRe: Is "New Year; New Me" ... Pin
theoldfool14-Jan-23 2:04
professionaltheoldfool14-Jan-23 2:04 
GeneralOi Griff ! Pin
pkfox13-Jan-23 23:38
professionalpkfox13-Jan-23 23:38 
GeneralRe: Oi Griff ! Pin
Richard MacCutchan14-Jan-23 0:14
mveRichard MacCutchan14-Jan-23 0:14 
GeneralRe: Oi Griff ! Pin
pkfox14-Jan-23 0:40
professionalpkfox14-Jan-23 0:40 
GeneralRe: Oi Griff ! Pin
Richard MacCutchan14-Jan-23 0:52
mveRichard MacCutchan14-Jan-23 0:52 
GeneralRe: Oi Griff ! Pin
pkfox14-Jan-23 21:49
professionalpkfox14-Jan-23 21:49 
GeneralRe: Oi Griff ! Pin
Richard MacCutchan14-Jan-23 21:56
mveRichard MacCutchan14-Jan-23 21:56 
GeneralRe: Oi Griff ! Pin
pkfox14-Jan-23 23:59
professionalpkfox14-Jan-23 23:59 

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.