3 ms·
The interface on our object (O) that you are describing is: O -> int Your unit test is concerned with narrowing the interface above to: O -> int // o
by kingdomcome50 6y ago
The interface on our object (O) that you are describing is:
O -> int
Your unit test is concerned with narrowing the interface above to:
O -> int // of specific value based on dependencies
If Os only dependencies are A and C, this can be rewritten to:
A -> C -> int // of specific value
Of course if we assume both A and C, themselves, have dependencies we can recursively rewrite the above until we have a very long interface, but instead you have opted to mock (M) them:
M(A) -> M(C) -> int // of specific value
You then take it a step further and mock the method calls on each to return a specific value:
M(A) -> int
M(B) -> int
becomes:
M(A) -> 3
M(B) -> 5
Okay. Now we can rewrite our interface to:
3 -> 5 -> int // of specific number
and our test to:
3 -> 5 -> 8
and make our assertion that the result is indeed the sum of the inputs (not to mention the ridiculous assertions that specific methods were called within the implementation). Yikes... No wonder OOP gets a bad wrap. All that for what amounts to a `sum` function.
The designer of the above monstrosity could learn a lot from the phrase "imperative shell, functional core". It sounds like dogma until you are knee deep in trying to test the middle of a large object graph!