Wednesday, August 14, 2019

Which Clojure test runner to use?

Photo by Genaro Servín from Pexels
Clojure has a built in test framework which works very well and for most of my Clojure experience it has done the job, until yesterday.  As part of a new project I needed to integrate with Bitbucket Pipeline, specifically I needed to run my unit tests and have the build fail on a failed test and report which test failed.  Bitbucket supports this integration.

The standard way to do this is to have the test runner create a XUnit compatible XML file and have the CI tool consume this file to produce the reports.  Unfortunately, the junit.xml file created by the default Clojure test runner creates a junit.xml that does not follow the spec and Bitbucket doesn't report which tests failed.

After some research, I found that Kaocha does a much better job of creating a junit.xml that Bitbucket Pipeline can grok.  In addition, it also supports code coverage which is a great bonus.

Here is the stanza for deps.edn to make it work:

:kaocha {:extra-paths ["test"]
:extra-deps {lambdaisland/kaocha {:mvn/version "0.0-529"}
lambdaisland/kaocha-junit-xml {:mvn/version "0.0-70"}
lambdaisland/kaocha-cloverage {:mvn/version "0.0-32"}
cloverage {:mvn/version "RELEASE"}
}
:main-opts ["-m" "kaocha.runner"
"--plugin" "kaocha.plugin/junit-xml"
"--plugin" "cloverage" "--no-cov-summary"
"--junit-xml-file" "target/test-results/junit.xml"]}
view raw kaocha-deps.edn hosted with ❤ by GitHub

No comments: