Fork me on GitHub
#testing
<
2019-07-10
>
Renan Oliveira03:07:48

@seancorfield Did you use midje for this kind tests?

seancorfield03:07:41

@renanrboliveira No, I don't like Midje 🙂

seancorfield03:07:00

I use the libraries I mentioned above.

Renan Oliveira03:07:58

Thanks 😃

seancorfield03:07:22

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

seancorfield03:07:14

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 Oliveira03:07:12

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

seancorfield03:07:19

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.

Jakub HolĂ˝ (HolyJak)05:07:40

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

seancorfield05:07:40

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

seancorfield05:07:19

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

Jakub HolĂ˝ (HolyJak)16:07:46

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Ă˝ (HolyJak)16:07:02

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

seancorfield17:07:12

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Ă˝ (HolyJak)17:07:34

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

lread13:07:00

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.