testing

Testing tools, testing philosophy & methodology...
dharrigan 2019-12-24T15:39:22.001800Z

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?

seancorfield 2019-12-24T20:27:07.003700Z

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

dharrigan 2019-12-24T20:59:56.004600Z

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

dharrigan 2019-12-24T21:00:23.005100Z

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

dharrigan 2019-12-24T21:00:48.005500Z

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

seancorfield 2019-12-24T21:07:37.006400Z

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

dharrigan 2019-12-24T22:12:45.006900Z

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

dharrigan 2019-12-24T22:12:50.007100Z

or does it not make sense?

seancorfield 2019-12-24T22:46:44.007400Z

with-redefs 🙂

seancorfield 2019-12-24T22:47:25.008200Z

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

seancorfield 2019-12-24T22:47:47.008700Z

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

dharrigan 2019-12-24T22:53:26.010Z

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