testing

Testing tools, testing philosophy & methodology...
valsen 2021-05-29T11:37:22.013Z

Hi, running my tests always returns with exit code 0 even when some tests fail. This makes running the test suite in CI useless. Am I doing something wrong or how do others run their tests in CI?

plexus 2021-05-30T07:22:23.015Z

You've basically created your own minimal test runner @josephson.victor :)

nbardiuk 2021-05-29T11:56:38.013100Z

lein test returns non zero error code when test fails. What do you use to run tests?

valsen 2021-05-29T11:57:25.013300Z

Ah I don’t use lein, my poject uses deps

valsen 2021-05-29T11:58:58.013500Z

right now my work-around looks something like this:

(defn -main []
  (let [{:keys [fail error]} (test-all)]
    (System/exit (if (zero? (+ fail error)) 0 1))))
And test-all is just a function that finds all my namespaces and runs (apply run-tests namespaces)

valsen 2021-05-29T12:00:09.013800Z

And I execute the program with clj -M:test . So, it kind of works thanks to the System/exit call but that feels like a hack

nbardiuk 2021-05-29T12:10:22.014Z

I don't use deps, but last time I've looked into it people used test runners like https://github.com/cognitect-labs/test-runner or https://github.com/lambdaisland/kaocha. With those you could remove logic that discovers tests and produces exit code

valsen 2021-05-29T12:14:55.014300Z

thanks I’ll check those out!:)

seancorfield 2021-05-29T16:58:42.014500Z

@josephson.victor We use Cognitect’s test-runner in our BitBucket Pipelines CI at work and like it a lot (especially now it has the -X / exec args invocation so we can merge test arguments across multiple aliases.

😃 1
seancorfield 2021-05-29T16:59:02.014700Z

(you can’t merge :main-opts across aliases — but you can merge :exec-args!)