Fork me on GitHub
#testing
<
2023-09-22
>
Ingy döt Net17:09:34

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")

Ingy döt Net17:09:28

Everything feels fine when tests pass.

Ingy döt Net17:09:28

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 🙂

respatialized17:09:55

When I find there's too much output I just use a let binding before the test expression

seancorfield17:09:16

You might like https://github.com/pjstadig/humane-test-output which improves the reporting in a lot of cases.

Ingy döt Net17:09:56

@UFTRLDZEW not sure I follow. Example?

Ingy döt Net17:09:30

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.

pesterhazy17:09:34

The actual expected and actual values are printed in the second line

seancorfield17:09:27

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

pesterhazy17:09:50

The way it's printed is a bit unorthodox but you get used to it

seancorfield17:09:39

That's why things like HTO got written and why there are also other test runners, like Kaocha, and other test libraries, like Expectations.

Ingy döt Net17:09:53

HTO looks promising

pesterhazy17:09:29

I use https://github.com/pesterhazy/elucidate when a failure is hard to read

👌 1
seancorfield17:09:40

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.

Ingy döt Net17:09:05

I made a really nice data driven testing lib over clojure.test, so I need something that works with clojure.test

Ingy döt Net17:09:21

HTO does, right?

seancorfield17:09:42

Expectations has two versions: the original standalone version and the clojure.test-compatible version. And, yes, HTO is an extension for clojure.test.

mpenet17:09:16

I like eftest nowadays. The defaults are quite nice, it’s simple and writing a custom runner or reporter is trivial

👍 1
mpenet17:09:19

Not to mention it can run tests in parallel (per var or ns)

Ingy döt Net18:09:56

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}

Ingy döt Net18:09:49

Thanks all. I'll check out the others someday 🙂

lread20:09:15

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!

lread20:09:34

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.

mauricio.szabo06:09:01

I really, really recommend matcher-combinators, even for simple things

👌 1
1
mpenet06:09:35

I quite like it as well