Fork me on GitHub

Is there a recommended approach to testing namespaces that use 3rd party libraries, such as a client to connect to a external resource, to "mock-out" that client? Say, for example, I have a function that uses the Elasticsearch Client (via interop), and I wish to test that function and mock out the call to the ES client, is there any recommendations?


@dharrigan You have to have a layer of abstraction in there somewhere to be able to mock it. Either a wrapper around the interop so you can mock the wrapper, or a protocol-based wrapper so you can have a test implementation of the protocol (although that's frowned upon by some people if you only have your single production implementation and are using the protocol purely for testing).


I see, - doesn't seem that wrong to use a protocol, it's to achieve something, i.e., to test 🙂


I'll have a play - thank you for the guidance 🙂


(also, not used protocols before, so a chance to learn :-))


Well, protocols are meant for when you have multiple (production) implementations and want fast dispatch based on type...


Is there no mocking framework, i.e., like mockito, but for Clojure?


or does it not make sense?


with-redefs 🙂


If you're using Component, you just build your system-under-test with test/mock versions of some components.


A mocking framework makes sense in an OOP language, not so much in a functional language.


I'm using Juxt Clip (a very lightweight alternative to Component) - so right now looking to see how to use that for mocking