Quote:
Originally Posted by suzzer99
Glob is a 3rd party module which is looking at the actual file system. How could I mock something like that?
"Don't mock what you don't own"
http://www.mockobjects.com/2007/04/t...is-mocked.html
If applicable, you can write a thin wrapper over the 3rd party module, which delegates to the 3rd party module, and mock your wrapper. Otherwise don't mock and do an integration test instead.
Quote:
Also initNodule is an internal method that is not exposed by the component. Is there any way to fake/spoof/spy on that?
you should never be writing tests for internal methods. if you find that you need to, or want to, it means something is wrong with your design. if it's truly "internal," then you should be testing it implicitly via the public methods that use it. if it's not truly internal, pull it out into its own class/function/module/blah or make it public, and test that. (EDIT: i should clarify here that this isn't free license to make all privates methods public. that's a design decision and shouldn't be influenced by your struggling with tests. that is, the testability should be giving you hints about the design. you shouldn't be bending your design thoughtlessly to achieve testability)
Quote:
Devs with lots of unit-test experience - to what level will you go to make your code more test-friendly if it means convoluting the code? Is this something you wouldn't even bother writing a test for because it's so low level and hard to mock/spy on?
i'll got to great lengths to make the code more testable, but not by convoluting my code. the test friendliness should be making the code simpler. if it's not, you have a problem.
Last edited by gaming_mouse; 12-28-2014 at 11:39 PM.