@seancorfield Did you use midje for this kind tests?
@renanrboliveira No, I don't like Midje đ
I use the libraries I mentioned above.
Thanks đ
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...
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.
I got it, I will study this libs, I agree what do you say.
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.
humm
Hi, what do you use to mock Java classes and interfaces (so that methods you don't care about return throw if called)?
I try to structure my code so I don't have to do that (because it's hard, at best).
@holyjak Can you give an example of what code you would want to mock Java classes in?
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.
So the code under test is something like (defn myfn [rest1..] (let [data (.gimmeData rest1)...] (compute data..)))
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"...
thanks, that's smart. I will remember it đ
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.