Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clojure test namespace convention

Tags:

clojure

I have traditionally used the same folder structure for production and test code as demonstrated below:

src/myproject/core.clj
test/myproject/core_test.clj

For test files I have added _test in the filename.

I recently noticed that several projects follow this structure (this is also what Leiningen generates by default):

src/myproject/core.clj
test/myproject/test/core.clj

Is there a convention regarding this or some clear advantage of using one over the other?

like image 954
ponzao Avatar asked Sep 20 '12 11:09

ponzao


1 Answers

I believe this is just convention - I don't think there is any technical advantage either way.

I personally prefer the first version for entirely non-technical reasons:

  • It seems redundant to have two "test" directories in the path.
  • It can cause confusion to have the test .clj files with the same names as the main .clj files
  • Sometimes you want to create tests that don't perfectly line up with specific namespaces, e.g. full_system_test.clj for end-to-end testing
  • It's easier to pattern-match on all the *_test.clj files

Also worth noting that the Maven standard directory layout convention is also used in quite a few Clojure projects (this can be handy if you build polyglot projects that also contain Java source code):

src/main/clojure/myproject/core.clj
src/test/clojure/myproject/core_test.clj
src/main/resources/....
src/test/resources/....
like image 87
mikera Avatar answered Nov 20 '22 20:11

mikera