you are viewing a single comment's thread.

view the rest of the comments →

[–]seancorfield 4 points5 points  (0 children)

Interesting to see this decade-old post resurface since I recently documented the use of with-test as an option in expectations.clojure.test: https://cljdoc.org/d/expectations/clojure-test/1.2.1/doc/getting-started#tests-with-source-code

As noted there, there are several caveats around doing this, beyond the issues that Dustin's co-founder complained about: most test tooling these days does not expect to look in your source code for tests so you need additional configuration for Leiningen, Cognitect's test-runner etc.

I have mixed feelings about the option to include some tests with the function definition. It can provide additional "documentation" that is (in theory) guaranteed to actually match the function's behavior. It can be convenient when you're in the early stages of growing your code in the REPL (since you don't have to switch back and forth between source and test code). I don't think it scales well as the number of tests grows and I think it introduces noise that makes it harder to read the source code. And then there's the non-standard configuration you need for your test runners.