Fork me on GitHub
#testing
<
2021-06-07
>
Leonid Korogodski18:06:08

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.

seancorfield19:06:40

@lkorogodski Because without -test you would have two files on the classpath with the same namespace — which doesn’t work.

Leonid Korogodski19:06:14

I addressed that in my question. They can be merged in test mode and not merged otherwise.

Leonid Korogodski19:06:35

That's how it is done in Java and Scala, for example. Same package can be used.

seancorfield19:06:05

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.

seancorfield19:06:34

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.

seancorfield19:06:12

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.

seancorfield19:06:01

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).

seancorfield19:06:52

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).