This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2023-09-22
Channels
- # babashka (106)
- # beginners (29)
- # biff (29)
- # calva (9)
- # cider (6)
- # clj-kondo (24)
- # clojure (40)
- # clojure-europe (94)
- # clojure-japan (1)
- # clojure-nl (1)
- # clojure-norway (45)
- # clojure-uk (13)
- # clojuredesign-podcast (5)
- # clojurescript (12)
- # clr (4)
- # community-development (2)
- # conjure (13)
- # cryogen (4)
- # cursive (4)
- # deps-new (1)
- # fulcro (18)
- # hugsql (2)
- # hyperfiddle (67)
- # jobs (1)
- # malli (47)
- # meander (2)
- # missionary (34)
- # off-topic (1)
- # podcasts-discuss (1)
- # polylith (24)
- # reagent (19)
- # reitit (9)
- # sci (7)
- # shadow-cljs (3)
- # testing (28)
- # tools-deps (1)
- # xtdb (9)
I feel like I'm setting my tests up wrong because I get failure results like:
expected: (= (testfn test) (expected test))
actual: (not (= "foo" "bar"))
when it feels like I should be seeing something like:
expected: ("bar")
actual: ("foo")
Everything feels fine when tests pass.
btw, I put foo bar
above but a real result is:
expected: (= (testfn test) (expected test))
actual: (not (= "{:type \"Mapping\",\n :coll\n ({:type \"Scalar\", :style \":\", :value \"a\"}\n {:type \"Scalar\", :style \":\", :value \"b c\"})}\n" "{:type \"Mapping\",\n :coll\n ({:type \"Scalar\", :style \":\", :value \"a\"}\n {:type \"Scalar\", :style \":\", :value \"b c\"})}X\n"))
which is madness 🙂When I find there's too much output I just use a let binding before the test expression
You might like https://github.com/pjstadig/humane-test-output which improves the reporting in a lot of cases.
@UFTRLDZEW not sure I follow. Example?
@U04V70XH6 I'll take a look
I just don't get why it's putting the testing code in expected
My testing function produces a string, so I want expected
to be the string I'm declaring to be expected, and actual
to be the output of my testing function.
The actual expected and actual values are printed in the second line
clojure.test
is pretty simplistic. If you say (is some-expression)
then that is the "expected" expression, and the "actual" result is (not value-of-some-expression)
.
The way it's printed is a bit unorthodox but you get used to it
That's why things like HTO got written and why there are also other test runners, like Kaocha, and other test libraries, like Expectations.
HTO looks promising
I liked Expectations enough that I took over maintenance of it 🙂 and I recommend HTO even with Expectations.
But clojure.test
's extension hooks are very primitive so there's a limit to what test runners can actually do.
I made a really nice data driven testing lib over clojure.test, so I need something that works with clojure.test
HTO does, right?
Expectations has two versions: the original standalone version and the clojure.test
-compatible version. And, yes, HTO is an extension for clojure.test
.
I like eftest nowadays. The defaults are quite nice, it’s simple and writing a custom runner or reporter is trivial
HTO is exactly what I wanted here! And trivial to add. No changes to my setup.
Testing yamlscript.composer-test
* test-1: Example Test
FAIL in (test-1) (test.clj:114)
expected: {:type "Mapping",
:coll
({:type "Scalar", :style ":", :value "a"}
{:type "Scalar", :style ":", :value "b c"})}
actual: {:type "Mapping",
:coll
({:type "Scalar", :style ":", :value "a"}
{:type "Scalar", :style ":", :value "b C"})}
diff: - {:coll [nil {:value "b c"}]}
+ {:coll [nil {:value "b C"}]}
Ran 1 tests containing 1 assertions.
1 failures, 0 errors.
{:test 1, :pass 0, :fail 1, :error 0, :type :summary}
Thanks all. I'll check out the others someday 🙂
https://github.com/lambdaisland/kaocha does nice reporting too. It is more of a complete replacement runner, so some folks find that too much, but I tend to like it!
And when you get into diffing more complex structures, I think that like me, you'll find https://github.com/nubank/matcher-combinators a complete joy.