testing

Testing tools, testing philosophy & methodology...
Leonid Korogodski 2021-06-07T18:59:08.018400Z

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.

seancorfield 2021-06-07T19:03:40.019Z

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

Leonid Korogodski 2021-06-07T19:04:14.019700Z

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

Leonid Korogodski 2021-06-07T19:04:35.020300Z

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

seancorfield 2021-06-07T19:05:05.020700Z

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.

Leonid Korogodski 2021-06-07T19:08:22.021400Z

Ok

seancorfield 2021-06-07T19:09:34.022500Z

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.

seancorfield 2021-06-07T19:10:12.023300Z

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.

seancorfield 2021-06-07T19:11:01.024400Z

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

seancorfield 2021-06-07T19:12:52.025Z

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