Why can't we use the exact same namespace structure in test
as in src
(and, for integration testing, in it
)? Why do we need to add the _test
suffix and have to require the original namespace? If we use the test code only when running tests--and if the files are merged when in test mode--then there would have been no confusion.
@lkorogodski Because without -test
you would have two files on the classpath with the same namespace — which doesn’t work.
I addressed that in my question. They can be merged in test mode and not merged otherwise.
That's how it is done in Java and Scala, for example. Same package can be used.
In Java/Scala, they are different classes in the same package: SomeClass
in the source tree and SomeClassTest
in the test tree. Which is “the same” as Clojure.
Ok
The -test
suffix is just a convention. You can call your test namespaces whatever you want. But all your namespaces on your classpath must be unique in Clojure — just as all your class names in Java/Scala on your classpath must be unique.
But if you use a different naming convention, the myriad test runners available in Clojure will have different ways to specify how to find/run tests.
You can have your tests in your source files if you want. But almost no one does that in Clojure. You can even have your tests as part of your (source) defn
expressions (but, again, almost no one does that).
https://cljdoc.org/d/expectations/clojure-test/1.2.1/doc/getting-started#test-placement talks about various ways to define and run your tests (it’s applicable to nearly all test runners).