testing

Testing tools, testing philosophy & methodology...
Renan Oliveira 2019-07-10T03:25:48.012100Z

@seancorfield Did you use midje for this kind tests?

seancorfield 2019-07-10T03:31:41.012500Z

@renanrboliveira No, I don't like Midje 🙂

seancorfield 2019-07-10T03:32:00.012900Z

I use the libraries I mentioned above.

Renan Oliveira 2019-07-10T03:43:58.013100Z

Thanks 😃

seancorfield 2019-07-10T03:47:22.014900Z

Midje is not compatible with clojure.test-based tooling. That was the problem with the original Expectations and why I wrote expectations/clojure-test -- to bring Expectations syntax to clojure.test so you could use all of the regular tooling with it: standard test runners, CIDER, Chlorine/ProtoREPL, Cursive...

seancorfield 2019-07-10T03:54:14.018700Z

FWIW, a lot of the Midje checker stuff has equivalents in expectations/clojure-test, such as (expect {:new-left {} :new-right {:a 1}} (in (migrate {:a 1} :a {}))) (expect #"a+b" "aab") and (expect even? 3) (a failure), taking examples from the Midje docs.

Renan Oliveira 2019-07-10T03:55:12.019100Z

I got it, I will study this libs, I agree what do you say.

seancorfield 2019-07-10T03:56:19.020100Z

Having tests that can be easily run via any of the standard tooling is very important. You need to be able to just run tests in your editor with a hot key, for example, no matter what your editor is.

Renan Oliveira 2019-07-10T03:57:03.020300Z

humm

Jakub HolĂ˝ 2019-07-10T05:00:40.022200Z

Hi, what do you use to mock Java classes and interfaces (so that methods you don't care about return throw if called)?

seancorfield 2019-07-10T05:02:40.022600Z

I try to structure my code so I don't have to do that (because it's hard, at best).

seancorfield 2019-07-10T05:04:19.023200Z

@holyjak Can you give an example of what code you would want to mock Java classes in?

Jakub HolĂ˝ 2019-07-10T16:29:46.025Z

I have a clj library replacing a part of a bigger Java app. Among my inputs are two "connectors" for backend REST services (that I don't want to reimplement in Clojure for reasons). Each has an interface and over 10 methods but my code only calls 1 or 2. So in my test I want to mock just those I call with the test data. I could just use Mockito.mock I guess but it seems, for my case, reify works well enough. To be clear, the classes only serve as sources of data.

Jakub HolĂ˝ 2019-07-10T16:32:02.025200Z

So the code under test is something like (defn myfn [rest1..] (let [data (.gimmeData rest1)...] (compute data..)))

seancorfield 2019-07-10T17:28:12.025400Z

I'd probably create a protocol for the parts of the API(s) I needed to call, then implement them as a wrapper around the Java classes, and then it's easy to provide a test wrapper as an alternative protocol implementation... but reify would likely be my first attempt to see whether that's "enough"...

Jakub HolĂ˝ 2019-07-10T17:56:34.025600Z

thanks, that's smart. I will remember it 🙂

lread 2019-07-10T13:22:00.024900Z

thanks @seancorfield, I’ve often seen the opinion “I don’t like Midje” but here you’ve also backed up that opinion with a reason that makes sense to me.