Fork me on GitHub
#testing
<
2019-12-24
>
dharrigan15:12:22

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?

seancorfield20:12:07

@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).

dharrigan20:12:56

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

dharrigan21:12:23

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

dharrigan21:12:48

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

seancorfield21:12:37

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

dharrigan22:12:45

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

dharrigan22:12:50

or does it not make sense?

seancorfield22:12:44

with-redefs 🙂

seancorfield22:12:25

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

seancorfield22:12:47

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

dharrigan22:12:26

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