**Diagram 1: Types of Code**
high
^ ||
^ ||
^ boring I/O || interesting I/O
^ ||
cost of testing ^ ================================
^ ||
^ ||
^ boring || interesting
^ transformation || transformation
^ ||
low >>>>>>>>>>>>>>>>>>>>>>>>>>>>> high
benefit of testing
Created
January 13, 2018 03:37
-
-
Save anonymous/b2b375c57aa469f9bab4488c40cf2950 to your computer and use it in GitHub Desktop.
Figures for Data Transformation is Good and Mocks are Smells
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Architecture 1 | |
function callApi(x, y, z) { | |
manipulate params | |
manipulate params some more ... | |
return fetch(...) | |
.then(result => { | |
if (result.status === ...) { | |
handle status stuff | |
} | |
manipulate result | |
manipulate result some more ... | |
return manipulatedResult | |
}) | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Architecture 2 | |
function callApi(x, y, z) { | |
const request = buildRequest(x, y, z) | |
return fetch(request) | |
.then(assertStatus('callApi', x, y, z)) | |
.then(parseResponse) |
**Diagram 2: Should I unit test?**
high
^ ||
^ ||
^ don't test || maybe test
^ ||
cost of testing ^ ================================
^ ||
^ ||
^ maybe test || should test
^ ||
^ ||
low >>>>>>>>>>>>>>>>>>>>>>>>>>>>> high
benefit of testing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test for Architecture 1 | |
fetch = spy().andMockWith(function (args) { | |
// pattern matching and pretend games | |
}) | |
assertSpyStuff | |
assertMoreSpyStuff | |
assertMoreSpyStuff |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Test for Architecture 2 | |
assert.deepEqual( | |
buildRequest(x, y, z), | |
expectedRequest | |
) | |
assert.deepEqual( | |
parseResponse(response), | |
expectedParsedResponse | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment