Search code examples
clojurefunctional-testingclojure.spec

To what extent is clojure.spec intended to replace traditional functional automation testing?


As screencasts and blogs start to appear around the new clojure.spec feature in Clojure 1.9, it's becoming clear that clojure.spec is capable of doing a lot of the risk mitigation that's previously been performed by more "traditional" automated testing libraries such as clojure.test, midje, speclj and test.check.

Is the intent that the capabilities of clojure.test will be essentially replicated within clojure.spec? If you were starting to build a new app today to run under Clojure 1.9+, would you be setting aside the testing libraries I listed above and instead relying solely on clojure.spec to give you a similar level of confidence around your app's behaviour?


Solution

  • Is the intent that the capabilities of clojure.test will be essentially replicated within clojure.spec?

    • No, the capabilities of clojure.test will be not replicated in clojure.spec
    • Example-based tests and generative tests are different tools for different needs, although there is overlap

    If you were starting to build a new app today to run under Clojure 1.9+, would you be setting aside the testing libraries I listed above and instead relying solely on clojure.spec to give you a similar level of confidence around your app's behaviour?

    • I will be using (and would suggest) both example-based and generative tests in most projects
    • However, I think there will be far fewer example-based tests when combining an example-based test suite with clojure.spec

    Why not all clojure.spec? (implied)

    • Some things are hard to spec
    • Some things are hard to write generators for
    • Having example input/output in a file is nice for people who are just reading the code
    • Unit tests are pretty much expected in most mature projects
    • And more

    Slightly off-topic, but just putting out a friendly reminder that clojure.spec has much more utility than reducing the number of unit test cases in a project.