Mateusz ?oskot
On 15 January 2014 20:08, Adam Sroka <adam.sroka@...> wrote:
Adam, I see your point, although it does not mean I immediately see where to plug it in my practice. ?
I do not mean to start any such debate, no. I am learning from many resources what you are saying, when/if to mock is matter of style and I have no reason to not to trust it is.
But, as soon as I get back to practising UT and I have an external dependency, i.e. remote service, mocking an obvious choice otherwise I can't see how I can continue testing my unit without either integrating
with real remote service or mocking it. Then I remember "mocking is matter of style" and I get confused immediately: does it mean I either test my unit with mocking or not test at all?
I hope you can trace the tracks of my thinking here. The a self-contained complete example I posted in which I'm trying to test xdep as external legacy, uses code
beyond my control. I can't change how xdep is designed. Let's try to simply it to get away from conceptual discussion on? techniques and methods, and get down to bare code: def exists(item_id): ? ? xdep.open() ?# opens some remote resource ? ? item = xdep.get_item(item_id) ? ? xdep.close() ? ? if item: ? ? ? ? return??== item_id ? ? else: ? ? ? ? return false Given id of an existing item,? When I call exists() Then it reports item does exists (return True) How would you test such function?
1. Mock the whole xdep (and set up all 3 functions as necessary for the scenario above). 2. Pick most relevant xdep function, namely the xdep.get_item and mock it? 3. No mocking at all? Then, how would you unit test exists function?
Best regards, -- Mateusz ??oskot, |