Fork me on GitHub
#testing
<
2020-08-09
>
jaime20:08:54

Hello, which tool will you recommend to see the diff in test assertions when they fail?

seancorfield20:08:55

Paul Stadig's Humane Test Output is fairly good for that (although there are some caveats around using it with Leiningen, since both tools try to modify the test reporting machinery -- so check the docs).

jaime20:08:29

Is it possible to integrate it with clojure cli? I'm not familiar with lein :injections, it seems like you have to call the (pjstadig.humane-test-output/activate!) in every test namespace?

seancorfield20:08:02

No, you only need to call that once, so you can use a :main-opts in your alias to do that.

seancorfield20:08:29

(if you use expectations/clojure-test it does that automatically for you, but I assume you're working with clojure.test and Cognitect's test-runner?)

vemv20:08:36

My approach is invoking https://github.com/lambdaisland/deep-diff2 or its predecessor, by hand, whenever I need it I'd understand the natural instict to automate this altogether but I don't think it has been accomplished in a clean and universal manner yet. IME, one truly wants a diff 1-3% of the time (which is still a lot!) so it's not particularly worth it to automate much.

seancorfield20:08:58

@vemv I agree to some extent. I do find that HTO makes some failures harder to read, but overall it makes many failures a lot better.

jaime20:08:59

@seancorfield I'm using clojure.test and running the test using intellij plugin cursive, it has a command to run the current deftest.

jaime20:08:35

Previously, cursive has a pop=up to show the diff, not sure why its not there anymore

onetom01:08:36

that diff is only available if the test failure follows a certain format. eg. it expects (is (= ... in the failure output. https://github.com/clojure-expectations/clojure-test prints (is (?= ... and that won't be recognized, so you won't see the Show diff... link

jaime21:08:54

:thinking_face: For this test failure, I think it should show the "show diff link" right?

seancorfield20:08:07

@jaime.sangcap I was just about to say: I thought Cursive already did that for you? Maybe ask in #cursive ?

seancorfield20:08:50

(I use Atom/Chlorine and I can run a single deftest too but rely on the REPL output window)

jaime20:08:18

Yes I'm thinking to ask it on that channel. I'm trying to improve the cursive experience a bit, at least to show the diff in the repl everytime I run the test using cursive